├── Auction ├── brownie-config.yaml ├── build │ ├── contracts │ │ ├── IERC721.json │ │ └── MyAuction.json │ └── deployments │ │ ├── 4 │ │ ├── 0x8816cd156792F4Fd9A081f14548D7Fa6040DfCf0.json │ │ ├── 0x896cFD0B138E93c8ce6260Bcc5910C67A0513Ec5.json │ │ └── 0xD2ff545E6E5B95DddA1795BA779C5ad866C2032C.json │ │ └── map.json ├── contracts │ ├── Auction.sol │ ├── Interfaces │ │ └── IERC721.sol │ └── README.md └── scripts │ ├── __pycache__ │ └── deploy.cpython-310.pyc │ └── deploy.py ├── Create2 └── contracts │ └── Create2Factory.sol ├── CrowdFund ├── brownie-config.yaml ├── build │ ├── contracts │ │ ├── CrowdFund.json │ │ ├── IERC20.json │ │ └── PureMath.json │ └── deployments │ │ ├── 4 │ │ ├── 0x579df29C056e4Bb9CD548EdEEB4b80CB4679b1Ec.json │ │ ├── 0x6B92295b20530d04F11D773AeA09F766a5E670c1.json │ │ └── 0x78727282cAbDA90176370416d9f75F58820B0d64.json │ │ └── map.json ├── contracts │ ├── CrowdFund.sol │ ├── Interfaces │ │ ├── IERC20.sol │ │ └── PureMath.sol │ └── README.md └── scripts │ ├── __pycache__ │ └── deploy.cpython-310.pyc │ └── deploy.py ├── Delegatecall ├── Delegatecall Deployed │ ├── brownie-config.yaml │ ├── build │ │ ├── contracts │ │ │ ├── Admin.json │ │ │ ├── Main.json │ │ │ ├── Proxy.json │ │ │ └── Store.json │ │ └── deployments │ │ │ ├── 4 │ │ │ └── 0xDC4Ddd0324C86C7167ECc906b9FbF4a1055F40fa.json │ │ │ └── map.json │ ├── contracts │ │ ├── Proxy.sol │ │ └── Utils │ │ │ ├── Admin.sol │ │ │ ├── Main.sol │ │ │ └── Store.sol │ └── scripts │ │ ├── __pycache__ │ │ └── deploy.cpython-310.pyc │ │ └── deploy.py ├── Delegatecall Source │ ├── Proxy.sol │ └── Utils │ │ ├── Admin.sol │ │ ├── Main.sol │ │ └── Store.sol ├── Deployment Address.txt └── Readme.md ├── Deployment Addresses.txt ├── DutchAuction ├── README.md ├── brownie-config.yaml ├── build │ ├── contracts │ │ ├── DutchAuction.json │ │ ├── IERC721.json │ │ └── SafeMath.json │ └── deployments │ │ ├── 4 │ │ └── 0x56aA4d97DA83b93372B6366482b929B86580452a.json │ │ └── map.json ├── contracts │ ├── DutchAuction.sol │ ├── Interfaces │ │ ├── IERC721.sol │ │ └── SafeMath.sol │ └── README.md └── scripts │ ├── __pycache__ │ └── deploy.cpython-310.pyc │ └── deploy.py ├── ERC20 ├── Deployment Addresses.txt ├── FPS2 Source │ └── contracts │ │ ├── FPS.sol │ │ ├── Interfaces │ │ └── IERC20.sol │ │ └── Libraries │ │ └── PureMath.sol └── FPS2 │ ├── brownie-config.yaml │ ├── build │ ├── contracts │ │ ├── FPS.json │ │ ├── IERC20.json │ │ └── PureMath.json │ ├── deployments │ │ ├── 4 │ │ │ └── 0x9af84a56B0b2444Fa2367C13862B652567CD0A1b.json │ │ └── map.json │ └── tests.json │ ├── contracts │ ├── FPS.sol │ ├── Interfaces │ │ └── IERC20.sol │ └── Libraries │ │ └── PureMath.sol │ ├── scripts │ ├── __pycache__ │ │ └── deploy.cpython-310.pyc │ └── deploy.py │ └── tests │ ├── __pycache__ │ └── test_erc.cpython-310-pytest-6.2.5.pyc │ └── test_erc.py ├── Faucet ├── brownie-config.yaml ├── build │ ├── contracts │ │ └── Faucet.json │ └── deployments │ │ ├── 4 │ │ └── 0x196ca425A223C5325d63e7245C93a284B6D5EA3c.json │ │ └── map.json ├── contracts │ └── Faucet.sol └── scripts │ ├── __pycache__ │ └── deploy.cpython-310.pyc │ └── deploy.py ├── New Faucet ├── brownie-config.yaml ├── build │ ├── contracts │ │ ├── Faucet.json │ │ └── SafeMath.json │ └── deployments │ │ ├── 4 │ │ └── 0x01f0E453B85A9F411166d486Ab645ff720A47335.json │ │ └── map.json ├── contracts │ ├── Faucet.sol │ └── Libraries │ │ └── SafeMath.sol └── scripts │ ├── __pycache__ │ └── deploy.cpython-310.pyc │ └── deploy.py ├── README.md ├── Random └── ExternalContractTest.sol ├── Sign.sol ├── StoreEmitAndRetrieve.sol ├── USDT ├── brownie-config.yaml ├── build │ ├── contracts │ │ ├── Context.json │ │ ├── IBEP20.json │ │ ├── Ownable.json │ │ ├── SafeMath.json │ │ └── USDT.json │ └── deployments │ │ ├── 4 │ │ ├── 0x770861CdcdDF8319C6C86ef8EF91C4A922fc12aC.json │ │ └── 0x788b76Ee23FAa205F3d4991C9977618Cc7c6a019.json │ │ └── map.json ├── contracts │ └── USDT.sol └── scripts │ ├── __pycache__ │ └── deploy.cpython-310.pyc │ └── deploy.py ├── bytecode.json ├── deploy.py ├── deployed AddressBook ├── AddressBook │ ├── brownie-config.yaml │ ├── build │ │ ├── contracts │ │ │ └── AddressBook.json │ │ ├── deployments │ │ │ ├── 4 │ │ │ │ ├── 0x395E24d23c52537B312373B53EbaF76259fCAB33.json │ │ │ │ ├── 0x4d6fa467d387bE828003f817bAb623526f027485.json │ │ │ │ ├── 0x51aa609240582C2Cf6B62dEf911FBbC6620641c5.json │ │ │ │ ├── 0x75827B81FE1D617553008D468184F6dB51B551A9.json │ │ │ │ └── 0x93a9b149A40490d03aA37de469105A8049932e30.json │ │ │ └── map.json │ │ └── tests.json │ ├── contracts │ │ └── AddressBook.sol │ ├── scripts │ │ ├── __pycache__ │ │ │ └── deploy.cpython-310.pyc │ │ └── deploy.py │ └── tests │ │ ├── __pycache__ │ │ └── test_addressbook.cpython-310-pytest-6.2.5.pyc │ │ └── test_addressbook.py └── Deployment Address.txt ├── erc20 - $AGU 2 ├── brownie-config.yaml ├── build │ ├── contracts │ │ ├── Aguia.json │ │ ├── IERC20.json │ │ └── PureMath.json │ └── deployments │ │ ├── 4 │ │ └── 0x183A9aA20E1596669BD81EacCDCe17E6705449f5.json │ │ └── map.json ├── contracts │ ├── Aguia.sol │ ├── Interfaces │ │ └── IERC20.sol │ └── Libraries │ │ └── PureMath.sol └── scripts │ ├── __pycache__ │ └── deploy.cpython-310.pyc │ └── deploy.py ├── erc20 - $AGU ├── brownie-config.yaml ├── build │ ├── contracts │ │ ├── AGU.json │ │ ├── Context.json │ │ ├── ERC20.json │ │ ├── IERC20.json │ │ └── IERC20Metadata.json │ └── deployments │ │ ├── 4 │ │ └── 0x2DFA0332E058c4FcC9d1b8C165eFf1CF52368d03.json │ │ └── map.json ├── contracts │ ├── Aguia.sol │ ├── Context.sol │ ├── ERC20.sol │ ├── IERC20.sol │ └── IERC20Metadata.sol └── scripts │ ├── __pycache__ │ └── deploy.cpython-310.pyc │ └── deploy.py ├── erc721 ├── brownie-config.yaml ├── build │ ├── contracts │ │ ├── IERC165.json │ │ ├── IERC721.json │ │ ├── IERC721Metadata.json │ │ ├── IERC721Receiver.json │ │ ├── Legio.json │ │ └── Strings.json │ └── deployments │ │ ├── 4 │ │ ├── 0x251568c2ba92a7CD30CF1f5a6c27dD42b167011A.json │ │ ├── 0xD17E6E1daB2d1E778278f5358ca68D572b713cdF.json │ │ └── 0xbc71d1049d984f261663c3b46c1F443C622852EF.json │ │ └── map.json ├── contracts │ ├── interfaces │ │ ├── IERC165.sol │ │ ├── IERC721.sol │ │ ├── IERC721Metadata.sol │ │ └── IERC721Receiver.sol │ ├── mynft.sol │ └── utils │ │ └── String.sol └── scripts │ ├── __pycache__ │ └── deploy.cpython-310.pyc │ └── deploy.py ├── ether_wallet ├── brownie-config.yaml ├── build │ ├── contracts │ │ └── EtherWallet.json │ └── deployments │ │ ├── 4 │ │ └── 0x72a8422a0E0098eF770A0dfdA312Ec1bd44fdB44.json │ │ └── map.json ├── contracts │ └── EtherWallet.sol └── scripts │ ├── __pycache__ │ └── deploy.cpython-310.pyc │ └── deploy.py ├── iterable_mapping ├── brownie-config.yaml ├── build │ ├── contracts │ │ └── IterableMapping.json │ └── deployments │ │ ├── 4 │ │ └── 0x1A09e937AB84b5434a70aDaBC69b9884B85ED123.json │ │ └── map.json ├── contracts │ └── IterableMapping.sol └── scripts │ ├── __pycache__ │ └── deploy.cpython-310.pyc │ └── deploy.py ├── libraries └── PureMath.sol ├── liquidity ├── IERC20.sol ├── IUniswapV2Factory.sol ├── IUniswapV2Pair.sol ├── IUniswapV2Router01.sol ├── IUniswapV2Router02.sol ├── IWETH.sol ├── SafeMath.sol ├── TransferHelper.sol ├── UniswapV2Library.sol └── UniswapV2Router02.sol ├── merkle_tree ├── Description.md ├── brownie-config.yaml ├── build │ ├── contracts │ │ └── MerkleTree.json │ └── deployments │ │ ├── 4 │ │ └── 0x7fF08E0dd90bBf3B22008fB1b28Bb4B037a8B79D.json │ │ └── map.json ├── contracts │ └── MerkleTree.sol └── scripts │ ├── __pycache__ │ └── deploy.cpython-310.pyc │ └── deploy.py ├── multi_sig_wallet ├── brownie-config.yaml ├── build │ ├── contracts │ │ └── MultiSigWallet.json │ └── deployments │ │ ├── 4 │ │ └── 0x14C6Bb868EB71cAaDf19601699C760926511578F.json │ │ └── map.json ├── contracts │ └── MultiSigWallet.sol └── scripts │ ├── __pycache__ │ └── deploy.cpython-310.pyc │ └── deploy.py └── token_task ├── brownie-config.yaml ├── build ├── contracts │ ├── Cix.json │ ├── Context.json │ ├── IBEP20.json │ ├── IERC20.json │ ├── IUniswapV2Factory.json │ ├── IUniswapV2Pair.json │ ├── IUniswapV2Router01.json │ ├── IUniswapV2Router02.json │ ├── Ownable.json │ ├── PureMath.json │ ├── SafeMath.json │ ├── Taxes.json │ └── USDT.json └── deployments │ └── map.json ├── contracts ├── Cix.sol ├── IERC20.sol ├── Liquidity.sol ├── Taxes.sol └── libraries │ ├── PureMath.sol │ └── USDT.sol └── scripts ├── __pycache__ └── deploy.cpython-310.pyc └── deploy.py /Auction/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /Auction/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "MyAuction": [ 4 | "0xD2ff545E6E5B95DddA1795BA779C5ad866C2032C", 5 | "0x896cFD0B138E93c8ce6260Bcc5910C67A0513Ec5", 6 | "0x8816cd156792F4Fd9A081f14548D7Fa6040DfCf0" 7 | ] 8 | } 9 | } -------------------------------------------------------------------------------- /Auction/contracts/Interfaces/IERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >0.6.0; 4 | 5 | interface IERC721 { 6 | function safeTransferFrom( 7 | address from, 8 | address to, 9 | uint tokenId 10 | ) external; 11 | 12 | function transferFrom( 13 | address, 14 | address, 15 | uint 16 | ) external; 17 | } -------------------------------------------------------------------------------- /Auction/contracts/README.md: -------------------------------------------------------------------------------- 1 | ## Overview. 2 | 3 | - ## English auction for NFT. 4 | 5 | ## Auction: 6 | - Seller of NFT deploys this contract. 7 | - Auction lasts for 7 days. 8 | - Participants can bid by depositing ETH greater than the current highest bidder. 9 | - All bidders can withdraw their bid if it is not the current highest bid. 10 | 11 | 12 | ## After the auction: 13 | - Highest bidder becomes the new owner of NFT. 14 | - The seller receives the highest bid of ETH. -------------------------------------------------------------------------------- /Auction/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/Auction/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /Auction/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import MyAuction, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract MyAuction...") 8 | deploy_wallet = MyAuction.deploy("0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593", 12345678, {"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "r+") as dep: 12 | dep.write("\n\nMyAuction => https://rinkeby.etherscan.io/address/"+deploy_wallet.address) 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /Create2/contracts/Create2Factory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | /// @dev Contract to be deployed with Create2. 5 | contract DeployWithCreate2 { 6 | address public owner; 7 | uint public f; 8 | 9 | constructor (address _owner, uint e) { 10 | owner = _owner; 11 | f = e; 12 | } 13 | 14 | function selfDestruct() public { 15 | selfdestruct(payable(msg.sender)); 16 | } 17 | } 18 | 19 | /// @dev Contract deploying with Create2. 20 | contract Create2Factory { 21 | event Deploy(address addr); 22 | address public _add; 23 | 24 | /** 25 | * @dev Deploy using any salt of user choice. 26 | * When deployed with this function using a 27 | * particular salt, and that same salt is used 28 | * again, this throws an error. 29 | * Also, when deployed with this function using 30 | * a particular salt, and that same salt is used 31 | * in the deployWithAssemblyCreate2, it also 32 | * throws an error. 33 | * 34 | * @param _salt A random uint256. 35 | */ 36 | function deploy(uint256 _salt) public { 37 | DeployWithCreate2 _contract = new DeployWithCreate2 { 38 | salt: bytes32(_salt) 39 | }(msg.sender, 6); 40 | emit Deploy(address(_contract)); 41 | } 42 | 43 | /** 44 | * @dev Returns the pre-calculated address of the contract 45 | * to be deployed using Create2. 46 | * 47 | * @param bytecode Compiled bytecode of contract to be 48 | * deployed. 49 | * @param _salt A random uint256. 50 | * 51 | * @return address Pre-calculated address. 52 | */ 53 | function getAddress(bytes memory bytecode, uint256 _salt) public view returns(address) { 54 | bytes32 hash = keccak256( 55 | abi.encodePacked( 56 | bytes1(0xff), 57 | address(this), 58 | _salt, 59 | keccak256(bytecode) 60 | ) 61 | ); 62 | 63 | return address(uint160(uint(hash))); 64 | } 65 | 66 | /** 67 | * @dev Returns the bytecode of the contract to be deployed 68 | * along with its constructor parameters. 69 | * 70 | * @return bytecode Contract bytecode. 71 | */ 72 | function getBytecode() public view returns(bytes memory bytecode) { 73 | bytes memory cCode = type(DeployWithCreate2).creationCode; 74 | bytecode = abi.encodePacked(cCode, abi.encode(msg.sender, 6)); 75 | // bytecode = abi.encodePacked(cCode, abi.encode(msg.sender), abi.encode(6)); 76 | } 77 | 78 | /** @dev Deploys with assembly create 2. 79 | * THIS IS THE PERK: 80 | * When this function is called first time, 81 | * the contract is deployed successfully, 82 | * returning and storing the address of the 83 | * deployed contract to `_add`. 84 | * Calling the deploy function above will throw 85 | * an error. 86 | * 87 | * However, after this function is called first 88 | * time and the above happens, storing the address 89 | * in the `_add` variable, when it is called again, 90 | * the transaction is successful, meaning a new 91 | * contract is deployed, but now, the new address 92 | * and the addresses of other subsequent deploys is 93 | * now a 0 address. Hence, the address in the `_add` 94 | * variable is replaced with a 0 address. 95 | * 96 | * @notice Address after first deployement with _salt as 6: 97 | * 0x9138AcCfF44091B80C53F35678188f90dc5494fb. 98 | * Address after calling the function a second time: 99 | * 0x0000000000000000000000000000000000000000. 100 | */ 101 | function deployWithAssemblyCreate2(uint256 _salt) public { 102 | bytes memory cCode = type(DeployWithCreate2).creationCode; 103 | bytes memory bytecode = abi.encodePacked(cCode, abi.encode(msg.sender, 6)); 104 | bytes32 salt = bytes32(_salt); 105 | address _address; 106 | assembly { 107 | _address := create2(0, add(bytecode, 32), mload(bytecode), salt) 108 | } 109 | _add = _address; 110 | } 111 | 112 | /// @dev Destruct the deployed contract. 113 | function destroy(address _a) public { 114 | DeployWithCreate2(_a).selfDestruct(); 115 | _add = address(0); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /CrowdFund/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /CrowdFund/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "CrowdFund": [ 4 | "0x579df29C056e4Bb9CD548EdEEB4b80CB4679b1Ec", 5 | "0x78727282cAbDA90176370416d9f75F58820B0d64", 6 | "0x6B92295b20530d04F11D773AeA09F766a5E670c1" 7 | ] 8 | } 9 | } -------------------------------------------------------------------------------- /CrowdFund/contracts/Interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) 3 | 4 | pragma solidity >0.6.0; 5 | 6 | /** 7 | * @dev Interface of the ERC20 standard as defined in the EIP. 8 | */ 9 | interface IERC20 { 10 | 11 | /** 12 | * @dev Moves `amount` tokens from the caller's account to `to`. 13 | * 14 | * Returns a boolean value indicating whether the operation succeeded. 15 | * 16 | * Emits a {Transfer} event. 17 | */ 18 | function transfer(address to, uint256 amount) external returns (bool); 19 | 20 | 21 | /** 22 | * @dev Moves `amount` tokens from `from` to `to` using the 23 | * allowance mechanism. `amount` is then deducted from the caller's 24 | * allowance. 25 | * 26 | * Returns a boolean value indicating whether the operation succeeded. 27 | * 28 | * Emits a {Transfer} event. 29 | */ 30 | function transferFrom( 31 | address from, 32 | address to, 33 | uint256 amount 34 | ) external returns (bool); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /CrowdFund/contracts/README.md: -------------------------------------------------------------------------------- 1 | ## Crowd Fund 2 | 3 | **Crowd fund ERC20 token** 4 | 5 | - User creates a campaign. 6 | - Users can pledge, transferring their token to a campaign. 7 | - After the campaign ends, campaign creator can claim the funds if total amount pledged is more than the campaign goal. 8 | - Otherwise, campaign did not reach it's goal, users can withdraw their pledge. -------------------------------------------------------------------------------- /CrowdFund/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/CrowdFund/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /CrowdFund/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import CrowdFund, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract CrowdFund...") 8 | deploy_wallet = CrowdFund.deploy({"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "a+") as dep: 12 | dep.write("\n\nCrowdFund => "+deploy_wallet.address) 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /Delegatecall/Delegatecall Deployed/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /Delegatecall/Delegatecall Deployed/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "Proxy": [ 4 | "0xDC4Ddd0324C86C7167ECc906b9FbF4a1055F40fa" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /Delegatecall/Delegatecall Deployed/contracts/Proxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | import "./Utils/Store.sol"; 5 | import "./Utils/Admin.sol"; 6 | 7 | 8 | /* 9 | * @title: Delegatecall Proxy. 10 | * @author: Anthony (fps) https://github.com/0xfps. 11 | * @dev: 12 | */ 13 | contract Proxy is Store, Admin { 14 | function add(uint _a, uint _b) public { 15 | address cont = current_contract; 16 | (bool sent, ) = cont.delegatecall( 17 | abi.encodeWithSignature( 18 | "add(uint256,uint256)", 19 | _a, 20 | _b 21 | ) 22 | ); 23 | require(sent, "Delegatecall, failed"); 24 | } 25 | 26 | function getTotal() public view returns(uint) { 27 | return total; 28 | } 29 | 30 | function gt() public view returns(address) { 31 | return current_contract; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Delegatecall/Delegatecall Deployed/contracts/Utils/Admin.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | /* 5 | * @title: Delegatecall Admin. 6 | * @author: Anthony (fps) https://github.com/0xfps. 7 | * @dev: 8 | */ 9 | 10 | contract Admin { 11 | address public current_contract; // Address of Main. 12 | mapping(address => bool) public admins; 13 | 14 | modifier isAdmin() { 15 | require(admins[msg.sender], "Not an admin"); 16 | _; 17 | } 18 | 19 | constructor() { 20 | admins[msg.sender] = true; 21 | } 22 | 23 | function acceptAdmin(address _address) public isAdmin { 24 | require(_address != address(0), "Zero address"); 25 | require(!admins[_address], "Already an admin"); 26 | 27 | admins[_address] = true; 28 | } 29 | 30 | function revokeAdmin(address _address) public isAdmin { 31 | require(_address != address(0), "Zero address"); 32 | require(admins[_address], "Not an admin"); 33 | 34 | admins[_address] = true; 35 | // require(_address != current_contract, "Same address"); 36 | // current_contract = new_contract; 37 | } 38 | 39 | function upgrade(address new_contract) public isAdmin { 40 | require(new_contract != address(0), "Zero address"); 41 | require(new_contract != current_contract, "Same address"); 42 | current_contract = new_contract; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Delegatecall/Delegatecall Deployed/contracts/Utils/Main.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | import "./Store.sol"; 5 | 6 | 7 | /* 8 | * @title: Delegatecall Main. 9 | * @author: Anthony (fps) https://github.com/0xfps. 10 | * @dev: 11 | */ 12 | contract Main is Store { 13 | function add(uint _a, uint _b) public { 14 | total = _a + _b; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Delegatecall/Delegatecall Deployed/contracts/Utils/Store.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | /* 5 | * @title: Delegatecall Store. 6 | * @author: Anthony (fps) https://github.com/0xfps. 7 | * @dev: Storage varaiable contract. 8 | */ 9 | contract Store { 10 | uint public total; 11 | } 12 | -------------------------------------------------------------------------------- /Delegatecall/Delegatecall Deployed/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/Delegatecall/Delegatecall Deployed/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /Delegatecall/Delegatecall Deployed/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import Proxy, accounts, network, config 2 | 3 | def deploy(): 4 | account = getAccount() 5 | 6 | print("Deploying...") 7 | 8 | deploy = Proxy.deploy({"from": account}, publish_source=True) 9 | 10 | 11 | print(f"Deployed at {deploy.address} !!!") 12 | 13 | title = "Proxy" 14 | link = "https://rinkeby.etherscan.io/address/" 15 | with open("../Deployment Address.txt", "a+") as file: 16 | file.write(f"{title} => {link}{deploy.address}\n\n") 17 | 18 | 19 | def getAccount(): 20 | if network.show_active() == "development": 21 | return accounts[0] 22 | else: 23 | return accounts.add(config['wallet']['from_key']) 24 | 25 | def main(): 26 | deploy() -------------------------------------------------------------------------------- /Delegatecall/Delegatecall Source/Proxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | import "./Utils/Store.sol"; 5 | import "./Utils/Admin.sol"; 6 | 7 | 8 | /* 9 | * @title: Delegatecall Proxy. 10 | * @author: Anthony (fps) https://github.com/0xfps. 11 | * @dev: 12 | */ 13 | contract Proxy is Store, Admin { 14 | function add(uint _a, uint _b) public { 15 | address cont = current_contract; 16 | (bool sent, ) = cont.delegatecall( 17 | abi.encodeWithSignature( 18 | "add(uint256,uint256)", 19 | _a, 20 | _b 21 | ) 22 | ); 23 | require(sent, "Delegatecall, failed"); 24 | } 25 | 26 | function getTotal() public view returns(uint) { 27 | return total; 28 | } 29 | 30 | function gt() public view returns(address) { 31 | return current_contract; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Delegatecall/Delegatecall Source/Utils/Admin.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | /* 5 | * @title: Delegatecall Admin. 6 | * @author: Anthony (fps) https://github.com/0xfps. 7 | * @dev: 8 | */ 9 | 10 | contract Admin { 11 | address public current_contract; // Address of Main. 12 | mapping(address => bool) public admins; 13 | 14 | modifier isAdmin() { 15 | require(admins[msg.sender], "Not an admin"); 16 | _; 17 | } 18 | 19 | constructor() { 20 | admins[msg.sender] = true; 21 | } 22 | 23 | function acceptAdmin(address _address) public isAdmin { 24 | require(_address != address(0), "Zero address"); 25 | require(!admins[_address], "Already an admin"); 26 | 27 | admins[_address] = true; 28 | } 29 | 30 | function revokeAdmin(address _address) public isAdmin { 31 | require(_address != address(0), "Zero address"); 32 | require(admins[_address], "Not an admin"); 33 | 34 | admins[_address] = true; 35 | // require(_address != current_contract, "Same address"); 36 | // current_contract = new_contract; 37 | } 38 | 39 | function upgrade(address new_contract) public isAdmin { 40 | require(new_contract != address(0), "Zero address"); 41 | require(new_contract != current_contract, "Same address"); 42 | current_contract = new_contract; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Delegatecall/Delegatecall Source/Utils/Main.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | import "./Store.sol"; 5 | 6 | 7 | /* 8 | * @title: Delegatecall Main. 9 | * @author: Anthony (fps) https://github.com/0xfps. 10 | * @dev: 11 | */ 12 | contract Main is Store { 13 | function add(uint _a, uint _b) public { 14 | total = _a + _b; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Delegatecall/Delegatecall Source/Utils/Store.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | /* 5 | * @title: Delegatecall Store. 6 | * @author: Anthony (fps) https://github.com/0xfps. 7 | * @dev: Storage varaiable contract. 8 | */ 9 | contract Store { 10 | uint public total; 11 | } 12 | -------------------------------------------------------------------------------- /Delegatecall/Deployment Address.txt: -------------------------------------------------------------------------------- 1 | Proxy => https://rinkeby.etherscan.io/address/0xDC4Ddd0324C86C7167ECc906b9FbF4a1055F40fa 2 | 3 | -------------------------------------------------------------------------------- /Delegatecall/Readme.md: -------------------------------------------------------------------------------- 1 | # Upgradable contracts with DelegateCall. 2 | 3 | ## Contents. 4 | - [ ] [Store.sol](https://github.com/0xfps/my-solidity/blob/main/Delegatecall/Delegatecall%20Source/Utils/Store.sol) 5 | - [ ] [Admin.sol](https://github.com/0xfps/my-solidity/blob/main/Delegatecall/Delegatecall%20Source/Utils/Admin.sol) 6 | - [ ] [Main.sol](https://github.com/0xfps/my-solidity/blob/main/Delegatecall/Delegatecall%20Source/Utils/Main.sol) 7 | - [ ] [Proxy.sol](https://github.com/0xfps/my-solidity/blob/main/Delegatecall/Delegatecall%20Source/Proxy.sol) 8 | 9 |
10 | 11 | ## Definitions. 12 | 13 | ### [Store.sol](https://github.com/0xfps/my-solidity/blob/main/Delegatecall/Delegatecall%20Source/Utils/Store.sol) 14 | 15 | > This contract stores all the state variables, so it is easy for the Proxy and the Main contracts to inherit the same storage stack. 16 | > This contract is inherited by the Main and the Proxy. 17 | 18 |
19 | 20 | ### [Admin.sol](https://github.com/0xfps/my-solidity/blob/main/Delegatecall/Delegatecall%20Source/Utils/Admin.sol) 21 | 22 | > This contract sets and changes the address of the Main contract whenever it is upgraded, it might be ownable with owner set to a particular address for Main contract deployement address change abilities. 23 | > This contract is inherited by the Proxy. 24 | 25 |
26 | 27 | 28 | ### [Main.sol](https://github.com/0xfps/my-solidity/blob/main/Delegatecall/Delegatecall%20Source/Utils/Main.sol) 29 | 30 | > This contract is where the main logic occurs, it reads and modifies the state variables of the Proxy via delegatecall. 31 | > This contract is not inherited. 32 | 33 |
34 | 35 | ### [Proxy.sol](https://github.com/0xfps/my-solidity/blob/main/Delegatecall/Delegatecall%20Source/Proxy.sol) 36 | 37 | > This is the contract that uses it's delegatecall function to get the Main to run it's logic using the state variables in it [Proxy]. 38 | > This contract is not inherited. 39 | ``` 40 | /// @dev Address of Main. 41 | address cont = current_contract; 42 | /// @dev Delegatecall using that address. 43 | /// @return bool. 44 | /// @return bytes memory. 45 | (bool sent, ) = cont.delegatecall( 46 | abi.encodeWithSignature( 47 | "add(uint256,uint256)", 48 | _a, 49 | _b 50 | ) 51 | ); 52 | /// @dev Ensure that the Delegatecall was successful. 53 | require(sent, "Delegatecall, failed"); 54 | ``` 55 | 56 |
57 | 58 | ## How To Deploy. 59 | - [x] Deploy Main first. 60 | - [x] Deploy Proxy 61 | - [x] Set the delegate call address to Main's deployment address. 62 | 63 | --- 64 | -------------------------------------------------------------------------------- /Deployment Addresses.txt: -------------------------------------------------------------------------------- 1 | Ether Wallet => https://rinkeby.etherscan.io/address/0x72a8422a0E0098eF770A0dfdA312Ec1bd44fdB44 2 | 3 | Merkle Tree => https://rinkeby.etherscan.io/address/0x7fF08E0dd90bBf3B22008fB1b28Bb4B037a8B79D 4 | 5 | Iterable Mapping => https://rinkeby.etherscan.io/address/0x1A09e937AB84b5434a70aDaBC69b9884B85ED123d0d0EC2 6 | 7 | FPS => https://rinkeby.etherscan.io/address/0x8EAB5027F9702d609f322C6c5285517f4516922c 8 | 9 | $AGU => https://rinkeby.etherscan.io/address/0x2DFA0332E058c4FcC9d1b8C165eFf1CF52368d03 10 | 11 | USDT => https://rinkeby.etherscan.io/address/0x788b76Ee23FAa205F3d4991C9977618Cc7c6a019f3b5F7f319EDF7C 12 | 13 | USDT => https://rinkeby.etherscan.io/address/0x770861CdcdDF8319C6C86ef8EF91C4A922fc12aC 14 | 15 | Legio 1 => https://rinkeby.etherscan.io/address/0x251568c2ba92a7CD30CF1f5a6c27dD42b167011A 16 | 17 | Legio 2 => https://rinkeby.etherscan.io/address/0xbc71d1049d984f261663c3b46c1F443C622852EF 18 | 19 | Legio 3 => https://rinkeby.etherscan.io/address/0xD17E6E1daB2d1E778278f5358ca68D572b713cdF 20 | 21 | Auction => https://rinkeby.etherscan.io/address/0x8816cd156792F4Fd9A081f14548D7Fa6040DfCf0 22 | 23 | DutchAuction => https://rinkeby.etherscan.io/address/0x56aA4d97DA83b93372B6366482b929B86580452a 24 | 25 | Multi Sig Wallet => https://rinkeby.etherscan.io/address/0x14C6Bb868EB71cAaDf19601699C760926511578F 26 | 27 | Aguia => https://rinkeby.etherscan.io/address/0x183A9aA20E1596669BD81EacCDCe17E6705449f5 28 | 29 | CrowdFund => https://rinkeby.etherscan.io/address/0x579df29C056e4Bb9CD548EdEEB4b80CB4679b1Ec 30 | 31 | Faucet => https://rinkeby.etherscan.io/address/0x196ca425A223C5325d63e7245C93a284B6D5EA3c -------------------------------------------------------------------------------- /DutchAuction/README.md: -------------------------------------------------------------------------------- 1 | ## **Dutch Auction** 2 | 3 | # Dutch auction for NFT. 4 | 5 | - Auction 6 | > - Seller of NFT deploys this contract setting a starting price for the NFT. 7 | > - Auction lasts for 7 days. 8 | > - Price of NFT decreases over time. 9 | > - Participants can buy by depositing ETH greater than the current price computed by the smart contract. 10 | > - Auction ends when a buyer buys the NFT. -------------------------------------------------------------------------------- /DutchAuction/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /DutchAuction/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "DutchAuction": [ 4 | "0x56aA4d97DA83b93372B6366482b929B86580452a" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /DutchAuction/contracts/DutchAuction.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | import "./Interfaces/IERC721.sol"; 5 | import "./Interfaces/SafeMath.sol"; 6 | 7 | /* 8 | * @title: DutchAuction Smart Contract [Modified]. 9 | * @author: Anthony (fps) https://github.com/0xfps. 10 | * @dev: Reference [README.md]. 11 | * @notice: Same as Auction [reference ./ Auction/Auction.sol] but with some differences. 12 | */ 13 | contract DutchAuction { 14 | // Use SafeMath for all uint256. 15 | using SafeMath for uint256; 16 | // Time of deployment. 17 | uint256 private deploy_time; 18 | // Time span of the contract, it reduces with time. 19 | uint256 private bid_time_span = 7 days; 20 | // Bool for still bidding. 21 | bool private still_bidding; 22 | // Depreciation interval, the time at which the price reduces. 23 | uint256 private interval_for_depreciation; 24 | // Time for last depreciation 25 | uint256 private last_depreciation; 26 | // Variable containing the price gone? 27 | uint256 private price_gone; 28 | // Bool to show that the bidding is locked. 29 | bool locked; 30 | // Nft address. 31 | IERC721 private nft; 32 | // Id of the nft to be sold. 33 | int256 private nft_id; 34 | // Starting bid for the nft. 35 | uint256 private starting_bid; 36 | // Seller of the nft, or whoever deploys the contract. 37 | address private seller; 38 | // The value of the depreciation. 39 | uint256 private depreciation; 40 | 41 | /* 42 | * @dev: 43 | * 44 | * Deploys the contract and sets the money used in the deployment as the base bidding price. 45 | * 46 | * 47 | * @param: 48 | * 49 | * address _nft_address -> Address of the nft to be deployed. 50 | * uint256 _nft_id -> Id of the nft you want to buy. 51 | */ 52 | constructor(address _nft_address, uint256 _nft_id) payable { 53 | // Initialize the nft. 54 | nft = IERC721(_nft_address); 55 | // Set the nft id. 56 | nft_id = int(_nft_id); 57 | // Starting bid for the nft. 58 | starting_bid = msg.value; 59 | // Set the owner or seller of the nft. 60 | seller = msg.sender; 61 | // Depreciation value set [Reference line 47], the value is or 0.001 ether. 62 | depreciation = 1_000_000 gwei; 63 | // Set interval for depreciation 64 | // interval_for_depreciation = 1 days; 65 | interval_for_depreciation = 5 seconds; 66 | // Set the last depreciation to the current time so that subsequent depreciations can be calculated. 67 | last_depreciation = block.timestamp; 68 | // Deploy time. 69 | deploy_time = block.timestamp; 70 | // Still bidding boolean value. 71 | still_bidding = true; 72 | } 73 | 74 | receive() payable external {} 75 | fallback() payable external {} 76 | 77 | /* 78 | * @dev: 79 | * 80 | * Validates that the address calling the function is a valid address and also not the seller. 81 | * Returns true if true, otherwise, false. 82 | */ 83 | function checkAddress() private view returns(bool) { 84 | return (msg.sender != address(0)) && ((msg.sender != seller)); 85 | } 86 | 87 | /* 88 | * @dev: 89 | * 90 | * This calculates and updates the new price of the item. 91 | */ 92 | function getPrice() private returns(uint256) { 93 | // First, get the time that has passed since the last depreciation till the time that this function is called. 94 | uint256 time_gone = block.timestamp - last_depreciation; 95 | // Assuming time gone is 100 seconds, and interval for depreciation is 10 seconds. 96 | // If it depreciates at 0.001 ether every interval, then total price gone will be (0.001 ether * (100secs/10secs)). 97 | price_gone = depreciation * (time_gone / interval_for_depreciation); 98 | 99 | // If the price gone is for some reasons, greater than the starting bid, meaning that tha price has floored. 100 | if(price_gone >= starting_bid) { 101 | // Set starting bid to 0. 102 | starting_bid = 0; 103 | } else { 104 | // Try to remove the price gone from the starting bid. 105 | (, uint256 j) = starting_bid.trySub(price_gone); 106 | // Set the new starting bid. 107 | starting_bid = j; 108 | } 109 | 110 | // Reset last depreciation to the current time. 111 | last_depreciation = block.timestamp; 112 | // Return the price gone. 113 | return price_gone; 114 | } 115 | 116 | /* 117 | * @dev: 118 | * 119 | * Buy the nft. 120 | */ 121 | function buy() public payable { 122 | // Makes sure that the bidding is still on, 123 | require(still_bidding, "Bid closed"); 124 | // Get updated price. 125 | uint256 price = getPrice(); 126 | // Makes sure address is legit. 127 | require(checkAddress(), "Bid cant be made by this address"); 128 | // Make sure that ether sent is greater than listed price of nft. 129 | require(msg.value >= price, "Bid < Starting bid."); 130 | // Transfer NFT to new owner. 131 | nft.transferFrom(seller, msg.sender, uint(nft_id)); 132 | // Calculate refunds. 133 | uint256 refund = msg.value - price; 134 | 135 | // If the refund is > 0. 136 | if(refund > 0) { 137 | // Refund the buyer. 138 | payable(msg.sender).transfer(refund); 139 | } 140 | 141 | // Reset nft address and destroy the nft id. 142 | nft_id = nft_id - (nft_id + 5); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /DutchAuction/contracts/Interfaces/IERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >0.6.0; 4 | 5 | interface IERC721 { 6 | function safeTransferFrom( 7 | address from, 8 | address to, 9 | uint tokenId 10 | ) external; 11 | 12 | function transferFrom( 13 | address, 14 | address, 15 | uint 16 | ) external; 17 | } -------------------------------------------------------------------------------- /DutchAuction/contracts/Interfaces/SafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/math/SafeMath.sol) 3 | 4 | pragma solidity >0.6.0; 5 | 6 | // CAUTION 7 | // This version of SafeMath should only be used with Solidity 0.8 or later, 8 | // because it relies on the compiler's built in overflow checks. 9 | 10 | /** 11 | * @dev Wrappers over Solidity's arithmetic operations. 12 | * 13 | * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler 14 | * now has built in overflow checking. 15 | */ 16 | library SafeMath { 17 | /** 18 | * @dev Returns the addition of two unsigned integers, with an overflow flag. 19 | * 20 | * _Available since v3.4._ 21 | */ 22 | function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { 23 | unchecked { 24 | uint256 c = a + b; 25 | if (c < a) return (false, 0); 26 | return (true, c); 27 | } 28 | } 29 | 30 | /** 31 | * @dev Returns the subtraction of two unsigned integers, with an overflow flag. 32 | * 33 | * _Available since v3.4._ 34 | */ 35 | function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { 36 | unchecked { 37 | if (b > a) return (false, 0); 38 | return (true, a - b); 39 | } 40 | } 41 | 42 | /** 43 | * @dev Returns the multiplication of two unsigned integers, with an overflow flag. 44 | * 45 | * _Available since v3.4._ 46 | */ 47 | function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { 48 | unchecked { 49 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 50 | // benefit is lost if 'b' is also tested. 51 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 52 | if (a == 0) return (true, 0); 53 | uint256 c = a * b; 54 | if (c / a != b) return (false, 0); 55 | return (true, c); 56 | } 57 | } 58 | 59 | /** 60 | * @dev Returns the division of two unsigned integers, with a division by zero flag. 61 | * 62 | * _Available since v3.4._ 63 | */ 64 | function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { 65 | unchecked { 66 | if (b == 0) return (false, 0); 67 | return (true, a / b); 68 | } 69 | } 70 | 71 | /** 72 | * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. 73 | * 74 | * _Available since v3.4._ 75 | */ 76 | function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { 77 | unchecked { 78 | if (b == 0) return (false, 0); 79 | return (true, a % b); 80 | } 81 | } 82 | 83 | /** 84 | * @dev Returns the addition of two unsigned integers, reverting on 85 | * overflow. 86 | * 87 | * Counterpart to Solidity's `+` operator. 88 | * 89 | * Requirements: 90 | * 91 | * - Addition cannot overflow. 92 | */ 93 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 94 | return a + b; 95 | } 96 | 97 | /** 98 | * @dev Returns the subtraction of two unsigned integers, reverting on 99 | * overflow (when the result is negative). 100 | * 101 | * Counterpart to Solidity's `-` operator. 102 | * 103 | * Requirements: 104 | * 105 | * - Subtraction cannot overflow. 106 | */ 107 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 108 | return a - b; 109 | } 110 | 111 | /** 112 | * @dev Returns the multiplication of two unsigned integers, reverting on 113 | * overflow. 114 | * 115 | * Counterpart to Solidity's `*` operator. 116 | * 117 | * Requirements: 118 | * 119 | * - Multiplication cannot overflow. 120 | */ 121 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 122 | return a * b; 123 | } 124 | 125 | /** 126 | * @dev Returns the integer division of two unsigned integers, reverting on 127 | * division by zero. The result is rounded towards zero. 128 | * 129 | * Counterpart to Solidity's `/` operator. 130 | * 131 | * Requirements: 132 | * 133 | * - The divisor cannot be zero. 134 | */ 135 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 136 | return a / b; 137 | } 138 | 139 | /** 140 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 141 | * reverting when dividing by zero. 142 | * 143 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 144 | * opcode (which leaves remaining gas untouched) while Solidity uses an 145 | * invalid opcode to revert (consuming all remaining gas). 146 | * 147 | * Requirements: 148 | * 149 | * - The divisor cannot be zero. 150 | */ 151 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 152 | return a % b; 153 | } 154 | 155 | /** 156 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 157 | * overflow (when the result is negative). 158 | * 159 | * CAUTION: This function is deprecated because it requires allocating memory for the error 160 | * message unnecessarily. For custom revert reasons use {trySub}. 161 | * 162 | * Counterpart to Solidity's `-` operator. 163 | * 164 | * Requirements: 165 | * 166 | * - Subtraction cannot overflow. 167 | */ 168 | function sub( 169 | uint256 a, 170 | uint256 b, 171 | string memory errorMessage 172 | ) internal pure returns (uint256) { 173 | unchecked { 174 | require(b <= a, errorMessage); 175 | return a - b; 176 | } 177 | } 178 | 179 | /** 180 | * @dev Returns the integer division of two unsigned integers, reverting with custom message on 181 | * division by zero. The result is rounded towards zero. 182 | * 183 | * Counterpart to Solidity's `/` operator. Note: this function uses a 184 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 185 | * uses an invalid opcode to revert (consuming all remaining gas). 186 | * 187 | * Requirements: 188 | * 189 | * - The divisor cannot be zero. 190 | */ 191 | function div( 192 | uint256 a, 193 | uint256 b, 194 | string memory errorMessage 195 | ) internal pure returns (uint256) { 196 | unchecked { 197 | require(b > 0, errorMessage); 198 | return a / b; 199 | } 200 | } 201 | 202 | /** 203 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 204 | * reverting with custom message when dividing by zero. 205 | * 206 | * CAUTION: This function is deprecated because it requires allocating memory for the error 207 | * message unnecessarily. For custom revert reasons use {tryMod}. 208 | * 209 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 210 | * opcode (which leaves remaining gas untouched) while Solidity uses an 211 | * invalid opcode to revert (consuming all remaining gas). 212 | * 213 | * Requirements: 214 | * 215 | * - The divisor cannot be zero. 216 | */ 217 | function mod( 218 | uint256 a, 219 | uint256 b, 220 | string memory errorMessage 221 | ) internal pure returns (uint256) { 222 | unchecked { 223 | require(b > 0, errorMessage); 224 | return a % b; 225 | } 226 | } 227 | } -------------------------------------------------------------------------------- /DutchAuction/contracts/README.md: -------------------------------------------------------------------------------- 1 | ## **Dutch Auction** 2 | 3 | # Dutch auction for NFT. 4 | 5 | - Auction 6 | > - Seller of NFT deploys this contract setting a starting price for the NFT. 7 | > - Auction lasts for 7 days. 8 | > - Price of NFT decreases over time. 9 | > - Participants can buy by depositing ETH greater than the current price computed by the smart contract. 10 | > - Auction ends when a buyer buys the NFT. -------------------------------------------------------------------------------- /DutchAuction/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/DutchAuction/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /DutchAuction/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import DutchAuction, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract DutchAuction...") 8 | deploy_wallet = DutchAuction.deploy("0x2DFA0332E058c4FcC9d1b8C165eFf1CF52368d03", 12345678, {"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "a+") as dep: 12 | dep.write("\n\nDutchAuction => "+deploy_wallet.address) 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /ERC20/Deployment Addresses.txt: -------------------------------------------------------------------------------- 1 | $FPS => https://rinkeby.etherscan.io/address/0x9af84a56B0b2444Fa2367C13862B652567CD0A1b -------------------------------------------------------------------------------- /ERC20/FPS2 Source/contracts/FPS.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | import "./Interfaces/IERC20.sol"; 5 | import "./Libraries/PureMath.sol"; 6 | 7 | /* 8 | * @title: FPS ($FPS) An re-write of the ERC-20 token, $FPS. 9 | * @author: Anthony (fps) https://github.com/0xfps. 10 | * @dev: 11 | */ 12 | contract FPS is IERC20 { 13 | using PureMath for uint256; 14 | // Token data. 15 | string private _name; // FPS. 16 | string private _symbol; // $FPS. 17 | uint256 private _totalSupply; // 1_000_000. 18 | uint8 private _decimals; // 18. 19 | // Owner address and a mapping of owners that can perform actions with the token. 20 | address private _owner = 0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593; // My Ethereum wallet address for production. 21 | // address private _owner = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4; // My Fake Remix wallet address for development. 22 | mapping(address => bool) private _approved_owners; 23 | // Token holders and allowances. 24 | mapping(address => uint256) private _balances; // Change to private on production. 25 | mapping(address => mapping(address => uint256)) private _allowances; 26 | // Events 27 | event Create(address, uint256, string, uint256); // Address, time, name, supply. 28 | event Mint(address, uint256, uint256); // Address, time, supply. 29 | event Burn(address, uint256, uint256); // Address, time, supply. 30 | event Change(address, uint256, address); // Old address, time, new address. 31 | 32 | // Constructor 33 | constructor() { 34 | _name = "FPS"; 35 | _symbol = "$FPS"; 36 | _decimals = 18; 37 | _totalSupply = 1000000000 * (10 ** _decimals); 38 | // Give the owner all the token. 39 | _balances[_owner] = _totalSupply; 40 | _approved_owners[_owner] = true; 41 | emit Create(_owner, block.timestamp, _name, _totalSupply); 42 | } 43 | 44 | function name() public view returns (string memory __name) { 45 | __name = _name; 46 | } 47 | 48 | function symbol() public view returns(string memory __symbol) { 49 | __symbol = _symbol; 50 | } 51 | 52 | function decimals() public view returns(uint8 __decimals) { 53 | __decimals = _decimals; 54 | } 55 | 56 | function totalSupply() public view override returns(uint256 __totalSupply) { 57 | __totalSupply = _totalSupply; 58 | } 59 | 60 | function exists(address _account) private view returns(bool) { 61 | return _approved_owners[_account]; 62 | } 63 | 64 | /* 65 | * @dev Returns the amount of tokens owned by `account`. 66 | */ 67 | function balanceOf(address account) public view override returns(uint256) { 68 | // require(msg.sender != address(0), "!Address"); 69 | require(exists(account), "Account !Exists"); 70 | uint256 _balance_of = _balances[account]; 71 | return _balance_of; 72 | } 73 | 74 | function isOneOfTheTwo(address __owner, address __spender) private view returns(bool) { 75 | return((msg.sender == __owner) || msg.sender == __spender); 76 | } 77 | 78 | /** 79 | * @dev Moves `amount` tokens from the caller's account to `to`. 80 | * 81 | * Returns a boolean value indicating whether the operation succeeded. 82 | * 83 | * Emits a {Transfer} event. 84 | */ 85 | function transfer(address to, uint256 amount) public override returns(bool) { 86 | require(msg.sender != address(0), "!Address"); // Sender's address is not 0 address. 87 | require(exists(msg.sender), "Account !Exists"); // Sender exists in the records, even if he has 0 tokens. 88 | require(to != address(0), "Receiver !Address"); // Receiver isn't 0 address. 89 | require(amount > 0, "Amount == 0"); // Can't send empty token. 90 | require(_balances[msg.sender] >= amount, "Wallet funds < amount"); // Sender has more than he can send. 91 | _balances[msg.sender] = _balances[msg.sender].sub(amount); // Subtract from sender. 92 | _balances[to] = _balances[to].add(amount); // Add to receiver. 93 | _approved_owners[to] = true; 94 | emit Transfer(msg.sender, to, amount); 95 | return true; 96 | } 97 | 98 | /** 99 | * @dev Returns the remaining number of tokens that `spender` will be 100 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 101 | * zero by default. 102 | * 103 | * This value changes when {approve} or {transferFrom} are called. 104 | */ 105 | function allowance(address owner, address spender) public view override returns(uint256) { 106 | require(msg.sender != address(0), "!Address"); 107 | require(owner != address(0), "!Owner"); 108 | require(spender != address(0), "!Spender"); 109 | require(exists(owner), "!Owner"); 110 | require(exists(spender), "!Spender"); 111 | require(isOneOfTheTwo(owner, spender), "!Owner && !Spender)"); 112 | uint256 _allowance = _allowances[owner][spender]; 113 | return _allowance; 114 | } 115 | 116 | /** 117 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 118 | * 119 | * Returns a boolean value indicating whether the operation succeeded. 120 | * 121 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 122 | * that someone may use both the old and the new allowance by unfortunate 123 | * transaction ordering. One possible solution to mitigate this race 124 | * condition is to first reduce the spender's allowance to 0 and set the 125 | * desired value afterwards: 126 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 127 | * 128 | * Emits an {Approval} event. 129 | */ 130 | function approve(address spender, uint256 amount) public override returns(bool) { 131 | // msg.sender == the address of the caller. 132 | require(msg.sender != address(0), "!Address"); 133 | require(spender != address(0), "!Spender"); 134 | require(exists(msg.sender), "!Account Exists"); 135 | require(msg.sender != spender, "Caller == Spender"); 136 | require(_balances[msg.sender] >= amount, "Balance < Amount"); 137 | _allowances[msg.sender][spender] += amount; 138 | emit Approval(msg.sender, spender, amount); 139 | return true; 140 | } 141 | 142 | /** 143 | * @dev Moves `amount` tokens from `from` to `to` using the 144 | * allowance mechanism. `amount` is then deducted from the caller's 145 | * allowance. 146 | * 147 | * Returns a boolean value indicating whether the operation succeeded. 148 | * 149 | * The person calling transferFrom doesn't need to own tokens. 150 | * 151 | * Emits a {Transfer} event. 152 | */ 153 | function transferFrom( 154 | address from, 155 | address to, 156 | uint256 amount 157 | ) public override returns(bool) 158 | { 159 | require(msg.sender != address(0), "!Address"); 160 | require(from != address(0), "!From"); 161 | require(to != address(0), "!To"); 162 | require(exists(from), "From !Exists"); 163 | require(_allowances[from][msg.sender] >= amount, "Balance < Amount"); 164 | 165 | _balances[from] = _balances[from].sub(amount); 166 | _balances[to] = _balances[to].add(amount); 167 | _allowances[from][msg.sender] = _allowances[from][msg.sender].sub(amount); 168 | 169 | _approved_owners[to] = true; 170 | 171 | emit Transfer(from, to, amount); 172 | 173 | return true; 174 | } 175 | 176 | /* 177 | * @dev: {mint()} adds more tokens to the `_totalSupply`. 178 | */ 179 | function mint(uint256 amount) public { 180 | require(msg.sender == _owner, "!Owner"); 181 | uint256 _supply = amount * (10 ** _decimals); 182 | _totalSupply = _totalSupply.add(_supply); 183 | emit Mint(msg.sender, block.timestamp, _supply); 184 | } 185 | 186 | /* 187 | * @dev: burn() removes from the token 188 | */ 189 | function burn(uint256 amount) public { 190 | require(msg.sender == _owner, "!Owner"); 191 | uint256 _supply = amount * (10 ** _decimals); 192 | _totalSupply = _totalSupply.sub(_supply); 193 | emit Burn(msg.sender, block.timestamp, _supply); 194 | } 195 | 196 | /* 197 | * @dev: {changeOwner()} changes owner of token 198 | */ 199 | function changeOwner(address new_owner) public { 200 | require(msg.sender == _owner, "!Owner"); 201 | require(new_owner != _owner, "New Owner == Old owner"); 202 | _owner = new_owner; 203 | emit Change(msg.sender, block.timestamp, new_owner); 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /ERC20/FPS2 Source/contracts/Interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Interface of the ERC20 standard as defined in the EIP. 8 | */ 9 | interface IERC20 { 10 | /** 11 | * @dev Returns the amount of tokens in existence. 12 | */ 13 | function totalSupply() external view returns (uint256); 14 | 15 | /** 16 | * @dev Returns the amount of tokens owned by `account`. 17 | */ 18 | function balanceOf(address account) external view returns (uint256); 19 | 20 | /** 21 | * @dev Moves `amount` tokens from the caller's account to `to`. 22 | * 23 | * Returns a boolean value indicating whether the operation succeeded. 24 | * 25 | * Emits a {Transfer} event. 26 | */ 27 | function transfer(address to, uint256 amount) external returns (bool); 28 | 29 | /** 30 | * @dev Returns the remaining number of tokens that `spender` will be 31 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 32 | * zero by default. 33 | * 34 | * This value changes when {approve} or {transferFrom} are called. 35 | */ 36 | function allowance(address owner, address spender) external view returns (uint256); 37 | 38 | /** 39 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 40 | * 41 | * Returns a boolean value indicating whether the operation succeeded. 42 | * 43 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 44 | * that someone may use both the old and the new allowance by unfortunate 45 | * transaction ordering. One possible solution to mitigate this race 46 | * condition is to first reduce the spender's allowance to 0 and set the 47 | * desired value afterwards: 48 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 49 | * 50 | * Emits an {Approval} event. 51 | */ 52 | function approve(address spender, uint256 amount) external returns (bool); 53 | 54 | /** 55 | * @dev Moves `amount` tokens from `from` to `to` using the 56 | * allowance mechanism. `amount` is then deducted from the caller's 57 | * allowance. 58 | * 59 | * Returns a boolean value indicating whether the operation succeeded. 60 | * 61 | * Emits a {Transfer} event. 62 | */ 63 | function transferFrom( 64 | address from, 65 | address to, 66 | uint256 amount 67 | ) external returns (bool); 68 | 69 | /** 70 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 71 | * another (`to`). 72 | * 73 | * Note that `value` may be zero. 74 | */ 75 | event Transfer(address indexed from, address indexed to, uint256 value); 76 | 77 | /** 78 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 79 | * a call to {approve}. `value` is the new allowance. 80 | */ 81 | event Approval(address indexed owner, address indexed spender, uint256 value); 82 | } -------------------------------------------------------------------------------- /ERC20/FPS2/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /ERC20/FPS2/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "FPS": [ 4 | "0x9af84a56B0b2444Fa2367C13862B652567CD0A1b" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /ERC20/FPS2/build/tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "contracts": { 3 | "FPS": "455912e89d62d51dca9347ca244ad15ac68bac59", 4 | "PureMath": "1ce946f6a4eaa185320328620ccf999b9e86db7c" 5 | }, 6 | "tests": { 7 | "tests/test_erc.py": { 8 | "coverage": false, 9 | "isolated": false, 10 | "results": "....", 11 | "sha1": "f8ccde63163085a91c077f779dec48798d578baa", 12 | "txhash": [ 13 | "03fc5846375cd263b1becfca452c82a53c6d4723", 14 | "2965c856dca843e933e487db8a5ca925a54fe6c9", 15 | "2c74c4271908d692117d04913bd6d3ac7aa05941", 16 | "9ce9daa62f2b4c410ef865d2324afd4848fd1409" 17 | ] 18 | } 19 | }, 20 | "tx": { 21 | "03fc5846375cd263b1becfca452c82a53c6d4723": { 22 | "FPS": { 23 | "0": [ 24 | [ 25 | 34, 26 | 35, 27 | 49 28 | ], 29 | [ 30 | 65 31 | ], 32 | [] 33 | ] 34 | } 35 | }, 36 | "2965c856dca843e933e487db8a5ca925a54fe6c9": { 37 | "FPS": { 38 | "0": [ 39 | [ 40 | 11, 41 | 12, 42 | 13, 43 | 14, 44 | 15, 45 | 49 46 | ], 47 | [ 48 | 59 49 | ], 50 | [ 51 | 56, 52 | 57, 53 | 58 54 | ] 55 | ] 56 | } 57 | }, 58 | "2c74c4271908d692117d04913bd6d3ac7aa05941": { 59 | "FPS": { 60 | "0": [ 61 | [ 62 | 3, 63 | 4, 64 | 5, 65 | 49 66 | ], 67 | [ 68 | 53 69 | ], 70 | [ 71 | 52 72 | ] 73 | ] 74 | } 75 | }, 76 | "9ce9daa62f2b4c410ef865d2324afd4848fd1409": { 77 | "FPS": { 78 | "0": [ 79 | [ 80 | 27 81 | ], 82 | [ 83 | 62 84 | ], 85 | [] 86 | ] 87 | } 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /ERC20/FPS2/contracts/FPS.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | import "./Interfaces/IERC20.sol"; 5 | import "./Libraries/PureMath.sol"; 6 | 7 | /* 8 | * @title: FPS ($FPS) An re-write of the ERC-20 token, $FPS. 9 | * @author: Anthony (fps) https://github.com/0xfps. 10 | * @dev: 11 | */ 12 | contract FPS is IERC20 { 13 | using PureMath for uint256; 14 | // Token data. 15 | string private _name; // FPS. 16 | string private _symbol; // $FPS. 17 | uint256 private _totalSupply; // 1_000_000. 18 | uint8 private _decimals; // 18. 19 | // Owner address and a mapping of owners that can perform actions with the token. 20 | address private _owner = 0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593; // My Ethereum wallet address for production. 21 | // address private _owner = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4; // My Fake Remix wallet address for development. 22 | mapping(address => bool) private _approved_owners; 23 | // Token holders and allowances. 24 | mapping(address => uint256) private _balances; // Change to private on production. 25 | mapping(address => mapping(address => uint256)) private _allowances; 26 | // Events 27 | event Create(address, uint256, string, uint256); // Address, time, name, supply. 28 | event Mint(address, uint256, uint256); // Address, time, supply. 29 | event Burn(address, uint256, uint256); // Address, time, supply. 30 | event Change(address, uint256, address); // Old address, time, new address. 31 | 32 | // Constructor 33 | constructor() { 34 | _name = "FPS"; 35 | _symbol = "$FPS"; 36 | _decimals = 18; 37 | _totalSupply = 1000000000 * (10 ** _decimals); 38 | // Give the owner all the token. 39 | _balances[_owner] = _totalSupply; 40 | _approved_owners[_owner] = true; 41 | emit Create(_owner, block.timestamp, _name, _totalSupply); 42 | } 43 | 44 | function name() public view returns (string memory __name) { 45 | __name = _name; 46 | } 47 | 48 | function symbol() public view returns(string memory __symbol) { 49 | __symbol = _symbol; 50 | } 51 | 52 | function decimals() public view returns(uint8 __decimals) { 53 | __decimals = _decimals; 54 | } 55 | 56 | function totalSupply() public view override returns(uint256 __totalSupply) { 57 | __totalSupply = _totalSupply; 58 | } 59 | 60 | function exists(address _account) private view returns(bool) { 61 | return _approved_owners[_account]; 62 | } 63 | 64 | /* 65 | * @dev Returns the amount of tokens owned by `account`. 66 | */ 67 | function balanceOf(address account) public view override returns(uint256) { 68 | // require(msg.sender != address(0), "!Address"); 69 | require(exists(account), "Account !Exists"); 70 | uint256 _balance_of = _balances[account]; 71 | return _balance_of; 72 | } 73 | 74 | function isOneOfTheTwo(address __owner, address __spender) private view returns(bool) { 75 | return((msg.sender == __owner) || msg.sender == __spender); 76 | } 77 | 78 | /** 79 | * @dev Moves `amount` tokens from the caller's account to `to`. 80 | * 81 | * Returns a boolean value indicating whether the operation succeeded. 82 | * 83 | * Emits a {Transfer} event. 84 | */ 85 | function transfer(address to, uint256 amount) public override returns(bool) { 86 | require(msg.sender != address(0), "!Address"); // Sender's address is not 0 address. 87 | require(exists(msg.sender), "Account !Exists"); // Sender exists in the records, even if he has 0 tokens. 88 | require(to != address(0), "Receiver !Address"); // Receiver isn't 0 address. 89 | require(amount > 0, "Amount == 0"); // Can't send empty token. 90 | require(_balances[msg.sender] >= amount, "Wallet funds < amount"); // Sender has more than he can send. 91 | _balances[msg.sender] = _balances[msg.sender].sub(amount); // Subtract from sender. 92 | _balances[to] = _balances[to].add(amount); // Add to receiver. 93 | _approved_owners[to] = true; 94 | emit Transfer(msg.sender, to, amount); 95 | return true; 96 | } 97 | 98 | /** 99 | * @dev Returns the remaining number of tokens that `spender` will be 100 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 101 | * zero by default. 102 | * 103 | * This value changes when {approve} or {transferFrom} are called. 104 | */ 105 | function allowance(address owner, address spender) public view override returns(uint256) { 106 | require(msg.sender != address(0), "!Address"); 107 | require(owner != address(0), "!Owner"); 108 | require(spender != address(0), "!Spender"); 109 | require(exists(owner), "!Owner"); 110 | require(exists(spender), "!Spender"); 111 | require(isOneOfTheTwo(owner, spender), "!Owner && !Spender)"); 112 | uint256 _allowance = _allowances[owner][spender]; 113 | return _allowance; 114 | } 115 | 116 | /** 117 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 118 | * 119 | * Returns a boolean value indicating whether the operation succeeded. 120 | * 121 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 122 | * that someone may use both the old and the new allowance by unfortunate 123 | * transaction ordering. One possible solution to mitigate this race 124 | * condition is to first reduce the spender's allowance to 0 and set the 125 | * desired value afterwards: 126 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 127 | * 128 | * Emits an {Approval} event. 129 | */ 130 | function approve(address spender, uint256 amount) public override returns(bool) { 131 | // msg.sender == the address of the caller. 132 | require(msg.sender != address(0), "!Address"); 133 | require(spender != address(0), "!Spender"); 134 | require(exists(msg.sender), "!Account Exists"); 135 | require(msg.sender != spender, "Caller == Spender"); 136 | require(_balances[msg.sender] >= amount, "Balance < Amount"); 137 | _allowances[msg.sender][spender] += amount; 138 | emit Approval(msg.sender, spender, amount); 139 | return true; 140 | } 141 | 142 | /** 143 | * @dev Moves `amount` tokens from `from` to `to` using the 144 | * allowance mechanism. `amount` is then deducted from the caller's 145 | * allowance. 146 | * 147 | * Returns a boolean value indicating whether the operation succeeded. 148 | * 149 | * The person calling transferFrom doesn't need to own tokens. 150 | * 151 | * Emits a {Transfer} event. 152 | */ 153 | function transferFrom( 154 | address from, 155 | address to, 156 | uint256 amount 157 | ) public override returns(bool) 158 | { 159 | require(msg.sender != address(0), "!Address"); 160 | require(from != address(0), "!From"); 161 | require(to != address(0), "!To"); 162 | require(exists(from), "From !Exists"); 163 | require(_allowances[from][msg.sender] >= amount, "Balance < Amount"); 164 | 165 | _balances[from] = _balances[from].sub(amount); 166 | _balances[to] = _balances[to].add(amount); 167 | _allowances[from][msg.sender] = _allowances[from][msg.sender].sub(amount); 168 | 169 | _approved_owners[to] = true; 170 | 171 | emit Transfer(from, to, amount); 172 | 173 | return true; 174 | } 175 | 176 | /* 177 | * @dev: {mint()} adds more tokens to the `_totalSupply`. 178 | */ 179 | function mint(uint256 amount) public { 180 | require(msg.sender == _owner, "!Owner"); 181 | uint256 _supply = amount * (10 ** _decimals); 182 | _totalSupply = _totalSupply.add(_supply); 183 | emit Mint(msg.sender, block.timestamp, _supply); 184 | } 185 | 186 | /* 187 | * @dev: burn() removes from the token 188 | */ 189 | function burn(uint256 amount) public { 190 | require(msg.sender == _owner, "!Owner"); 191 | uint256 _supply = amount * (10 ** _decimals); 192 | _totalSupply = _totalSupply.sub(_supply); 193 | emit Burn(msg.sender, block.timestamp, _supply); 194 | } 195 | 196 | /* 197 | * @dev: {changeOwner()} changes owner of token 198 | */ 199 | function changeOwner(address new_owner) public { 200 | require(msg.sender == _owner, "!Owner"); 201 | require(new_owner != _owner, "New Owner == Old owner"); 202 | _owner = new_owner; 203 | emit Change(msg.sender, block.timestamp, new_owner); 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /ERC20/FPS2/contracts/Interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Interface of the ERC20 standard as defined in the EIP. 8 | */ 9 | interface IERC20 { 10 | /** 11 | * @dev Returns the amount of tokens in existence. 12 | */ 13 | function totalSupply() external view returns (uint256); 14 | 15 | /** 16 | * @dev Returns the amount of tokens owned by `account`. 17 | */ 18 | function balanceOf(address account) external view returns (uint256); 19 | 20 | /** 21 | * @dev Moves `amount` tokens from the caller's account to `to`. 22 | * 23 | * Returns a boolean value indicating whether the operation succeeded. 24 | * 25 | * Emits a {Transfer} event. 26 | */ 27 | function transfer(address to, uint256 amount) external returns (bool); 28 | 29 | /** 30 | * @dev Returns the remaining number of tokens that `spender` will be 31 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 32 | * zero by default. 33 | * 34 | * This value changes when {approve} or {transferFrom} are called. 35 | */ 36 | function allowance(address owner, address spender) external view returns (uint256); 37 | 38 | /** 39 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 40 | * 41 | * Returns a boolean value indicating whether the operation succeeded. 42 | * 43 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 44 | * that someone may use both the old and the new allowance by unfortunate 45 | * transaction ordering. One possible solution to mitigate this race 46 | * condition is to first reduce the spender's allowance to 0 and set the 47 | * desired value afterwards: 48 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 49 | * 50 | * Emits an {Approval} event. 51 | */ 52 | function approve(address spender, uint256 amount) external returns (bool); 53 | 54 | /** 55 | * @dev Moves `amount` tokens from `from` to `to` using the 56 | * allowance mechanism. `amount` is then deducted from the caller's 57 | * allowance. 58 | * 59 | * Returns a boolean value indicating whether the operation succeeded. 60 | * 61 | * Emits a {Transfer} event. 62 | */ 63 | function transferFrom( 64 | address from, 65 | address to, 66 | uint256 amount 67 | ) external returns (bool); 68 | 69 | /** 70 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 71 | * another (`to`). 72 | * 73 | * Note that `value` may be zero. 74 | */ 75 | event Transfer(address indexed from, address indexed to, uint256 value); 76 | 77 | /** 78 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 79 | * a call to {approve}. `value` is the new allowance. 80 | */ 81 | event Approval(address indexed owner, address indexed spender, uint256 value); 82 | } -------------------------------------------------------------------------------- /ERC20/FPS2/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/ERC20/FPS2/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /ERC20/FPS2/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import FPS, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract FPS...") 8 | deploy_wallet = FPS.deploy({"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "a+") as dep: 12 | dep.write("\n\nFPS => https://rinkeby.etherscan.io/address/"+deploy_wallet.address) 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /ERC20/FPS2/tests/__pycache__/test_erc.cpython-310-pytest-6.2.5.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/ERC20/FPS2/tests/__pycache__/test_erc.cpython-310-pytest-6.2.5.pyc -------------------------------------------------------------------------------- /ERC20/FPS2/tests/test_erc.py: -------------------------------------------------------------------------------- 1 | from brownie import FPS, network, accounts, reverts 2 | 3 | def getAccount(): 4 | acc = accounts[0] 5 | return acc 6 | 7 | def deploy(): 8 | acc = getAccount() 9 | dep = FPS.deploy({"from":acc}) 10 | return dep 11 | 12 | def getMain(value, number): 13 | val = value / (10 ** number) 14 | return val 15 | 16 | 17 | # Tests deployments and constructor settings. 18 | 19 | def testDeploy(): 20 | acc = getAccount() 21 | deps = deploy() 22 | 23 | decimals = deps.decimals() 24 | name = deps.name() 25 | symbol = deps.symbol() 26 | total_supply = deps.totalSupply() 27 | 28 | 29 | # Test for constructor settings. 30 | 31 | test_address = "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593" 32 | 33 | 34 | # Returns the address balance. 35 | 36 | test_address_balance = deps.balanceOf(test_address) 37 | 38 | main_test_balance = getMain(test_address_balance, decimals) 39 | 40 | 41 | # Test for fake balance. 42 | 43 | fake_bal = "" 44 | comp_fake_bal = "" 45 | 46 | with reverts(): 47 | fake_bal = deps.balanceOf(accounts[2]) 48 | 49 | 50 | assert decimals == 18 51 | assert name == "FPS" 52 | assert symbol == "$FPS" 53 | assert total_supply == 1000000000 * (10 ** 18) 54 | assert main_test_balance == 1 * (10 ** 9) 55 | assert comp_fake_bal == fake_bal 56 | 57 | 58 | 59 | def testTransfer(): 60 | acc = getAccount() 61 | deps = deploy() 62 | 63 | # Address to transfer to. 64 | 65 | amount = 100 * (10 ** 18) 66 | to = accounts[3] 67 | 68 | fake_bal = "" 69 | 70 | with reverts(): 71 | fake_transfer = deps.transfer(to, amount, {"from": acc}) 72 | 73 | transfer = deps.transfer(to, amount, {"from": "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593"}) 74 | 75 | bal = deps.balanceOf(to) 76 | main_bal = getMain(bal, 18) 77 | 78 | owner_bal = deps.balanceOf("0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593") 79 | main_owner_bal = getMain(owner_bal, 18) 80 | 81 | assert fake_bal == "" 82 | assert main_bal == 100 83 | assert main_owner_bal < 1 * (10 ** 9) 84 | assert main_owner_bal == (1 * (10 ** 9) - 100) 85 | 86 | 87 | 88 | def testApproveAllowanceAndTransferFrom(): 89 | acc = getAccount() 90 | deps = deploy() 91 | 92 | 93 | # Fake approved account. 94 | 95 | fake_acc = accounts[3] 96 | 97 | approved_address = accounts[6] 98 | approved_amount = 500 * (10 ** 18) 99 | 100 | deps.transfer(approved_address, 100 * (10 ** 18), {"from": "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593"}) 101 | 102 | fake_approve = False 103 | 104 | with reverts(): 105 | fake_approve = deps.approve(approved_address, approved_amount, {"from": acc}) 106 | 107 | approve = deps.approve(approved_address, approved_amount, {"from": "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593"}) 108 | 109 | 110 | 111 | fake_allowance = 0 112 | 113 | with reverts(): 114 | fake_allowance = deps.allowance(acc, fake_acc) 115 | fake_allowance = deps.allowance(acc, approved_address) 116 | 117 | 118 | allowance = deps.allowance("0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593", approved_address, {"from": "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593"}) 119 | main_allowance = getMain(allowance, 18) 120 | 121 | 122 | 123 | fake_transfer_from = 0 124 | 125 | with reverts(): 126 | fake_transfer_from = deps.transferFrom("0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593", accounts[8], 100 * ( 10 ** 18), {"from": accounts[7]}) 127 | 128 | 129 | transferFrom = deps.transferFrom("0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593", accounts[5], 100 * ( 10 ** 18), {"from": approved_address}) 130 | 131 | balance_of_5 = deps.balanceOf(accounts[5]) 132 | main_balance_of_5 = getMain(balance_of_5, 18) 133 | 134 | 135 | allowance_of_approved = deps.allowance("0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593", approved_address, {"from": "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593"}) 136 | main_allowance_of_approved = getMain(allowance_of_approved, 18) 137 | 138 | _bal = deps.balanceOf("0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593") 139 | main__bal = getMain(_bal, 18) 140 | 141 | 142 | assert fake_approve == False 143 | assert fake_allowance == 0 144 | assert main_allowance == 500 145 | assert fake_transfer_from == 0 146 | assert main_balance_of_5 == 100 147 | assert main_allowance_of_approved == 400 148 | assert main__bal == (1 * (10 ** 9) - 200) 149 | 150 | 151 | 152 | def testMintAndBurn(): 153 | acc = getAccount() 154 | deps = deploy() 155 | 156 | mint_val = 1000 157 | burn_val = 200 158 | 159 | fake_mint = False 160 | 161 | with reverts(): 162 | deps.mint(mint_val, {"from": accounts[9]}) 163 | fake_mint = True 164 | 165 | deps.mint(mint_val, {"from": "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593"}) 166 | deps.burn(burn_val, {"from": "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593"}) 167 | 168 | tot = deps.totalSupply() 169 | main_tot = getMain(tot, 18) 170 | 171 | bal = deps.balanceOf("0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593") 172 | main_bal = getMain(bal, 18) 173 | 174 | assert main_tot == ((1 * (10 ** 9)) + 1000 - 200) -------------------------------------------------------------------------------- /Faucet/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /Faucet/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "Faucet": [ 4 | "0x196ca425A223C5325d63e7245C93a284B6D5EA3c" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /Faucet/contracts/Faucet.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | library SafeMath { 5 | /** 6 | * @dev Returns the addition of two unsigned integers, with an overflow flag. 7 | * 8 | * _Available since v3.4._ 9 | */ 10 | function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { 11 | unchecked { 12 | uint256 c = a + b; 13 | if (c < a) return (false, 0); 14 | return (true, c); 15 | } 16 | } 17 | 18 | /** 19 | * @dev Returns the subtraction of two unsigned integers, with an overflow flag. 20 | * 21 | * _Available since v3.4._ 22 | */ 23 | function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { 24 | unchecked { 25 | if (b > a) return (false, 0); 26 | return (true, a - b); 27 | } 28 | } 29 | } 30 | 31 | 32 | /* 33 | * @title: Rinkeby Test Faucet [Modified]. 34 | * @author: Anthony (fps) https://github.com/0xfps. 35 | * @dev: 36 | * 37 | * I once wrote this contract to deposit any specific amount of ether from the contract. 38 | * But on this mod [28/05/2022] I am re-writing it to actually dispose some specific ether 0.2 ether. 39 | * But it shall demand just 1 ether for fundings. 40 | */ 41 | contract Faucet { 42 | // Use SafeMath for all uint. 43 | using SafeMath for uint256; 44 | // Faucet has no owner. 45 | // Collections, that is the total amount that a particular address has collected from the Faucet. 46 | mapping (address => uint256) private collections; 47 | // Funders, the total amount that a particular address has donated to the Faucet. 48 | mapping (address => uint256) private funders; 49 | // Time, the last time a particular address withdrew. Addresses can withdraw ether every 12 hours. 50 | mapping (address => uint256) private time; 51 | // Array of the addresses that have donated to the faucet. 52 | address[] public donators; 53 | // Balance of the contract. 54 | uint256 private balance; 55 | // Interval that is 12 hours. 56 | uint256 private interval = 12 hours; 57 | // uint256 private interval = 1 seconds; 58 | // Boolean to check for Re-Entrancy attacks. 59 | bool locked; 60 | // Emitted when someone funds the contract. 61 | event Fund(address indexed __funder, uint256 indexed __fund); 62 | // Emitted when the contract pays someone. 63 | event Pay(address indexed __receiver, uint256 indexed __fund); 64 | 65 | receive() external payable{} 66 | fallback() external payable{} 67 | 68 | // Checks for Re-Entrancy attacks. 69 | modifier noReEntrance() { 70 | // Requires that the locked is set to false. 71 | require(!locked, "No ReEntrance"); 72 | // Lock the function. 73 | locked = true; 74 | // Execute. 75 | _; 76 | // Re-open the lock. 77 | locked = false; 78 | } 79 | 80 | // Checks if the address is in the donators array for a new push. 81 | function hasDonated(address _address) private view returns(bool) { 82 | // Push the length of the donators array to memory. 83 | uint256 l = donators.length; 84 | 85 | // Loop over the array 86 | for (uint256 k = 0; k < l; k++) { 87 | // If the donor exists in the array. 88 | if (donators[k] == _address) 89 | // Return true. 90 | return true; 91 | } 92 | 93 | // On loop end, that is, the donor is not in the array. 94 | return false; 95 | } 96 | 97 | /* 98 | * @dev: 99 | * 100 | * Funds any address on the condition that the time span of the last transaction to that address was 12 hours. 101 | */ 102 | function fund() public payable noReEntrance { 103 | // Ensure address donating isn't a 0 address. 104 | require(msg.sender != address(0), "!Address"); 105 | // Require that the donation is >= 1 ether. 106 | require(msg.value >= 1 ether, "Amount needed: 1 ether"); 107 | // Balance left after donation. 108 | uint bal = msg.value - 1 ether; 109 | // This should be == 1 ether but for confirmation purposes. 110 | uint _fund = msg.value - bal; 111 | // Record the funders value; 112 | // (, uint256 j) = funders[msg.sender].tryAdd(1 ether); 113 | (, uint256 j) = funders[msg.sender].tryAdd(_fund); 114 | // Update the funder value. 115 | funders[msg.sender] = j; 116 | // Increment the balance of the contract. 117 | // (, uint256 p) = balance.tryAdd(1 ether); 118 | (, uint256 p) = balance.tryAdd(_fund); 119 | // Update new balance. 120 | balance = p; 121 | 122 | // If the address has not donated before, it should be added to the donators array. 123 | if (!hasDonated(msg.sender)) { 124 | // Add the address to the array. 125 | donators.push(msg.sender); 126 | } 127 | 128 | // Emit the fund event. 129 | emit Fund(msg.sender, _fund); 130 | 131 | // If the balance is > 0. 132 | if (bal > 0) { 133 | // Refund the balance`. 134 | payable(msg.sender).transfer(bal); 135 | // Emit the pay event. 136 | emit Pay(msg.sender, bal); 137 | } 138 | } 139 | 140 | /* 141 | * @dev: 142 | * 143 | * This function requests for some ether from the faucet. 144 | * The faucet dispenses 0.2 ether for every address every 12 hours. 145 | */ 146 | function request() public payable noReEntrance { 147 | // Ensure address donating isn't a 0 address. 148 | require(msg.sender != address(0), "!Address"); 149 | // Make sure that the contract still has ether. 150 | require(balance > 0, "We have run out of ether"); 151 | // Get the requester's last request time. 152 | uint256 last_time = time[msg.sender]; 153 | // Make sure that the time passed is more than or == 12 hours. 154 | require((block.timestamp - last_time) > interval, "You can only withdraw every 12 hours!"); 155 | // Remove 0.2 ether from balance. 156 | (, uint256 p) = balance.trySub(0.2 ether); 157 | // Reassign new balance. 158 | balance = p; 159 | // Update the collections of the requester. 160 | (, uint j) = collections[msg.sender].trySub(0.2 ether); 161 | // Update the requesters collections. 162 | collections[msg.sender] = j; 163 | // Update the last request time. 164 | time[msg.sender] = block.timestamp; 165 | // Transfer the funds to the requester. 166 | payable(msg.sender).transfer(0.2 ether); 167 | // Emit the pay event. 168 | emit Pay(msg.sender, 0.2 ether); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /Faucet/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/Faucet/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /Faucet/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import Faucet, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract Faucet...") 8 | deploy_wallet = Faucet.deploy({"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "a+") as dep: 12 | dep.write("\n\nFaucet => "+deploy_wallet.address) 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /New Faucet/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /New Faucet/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "Faucet": [ 4 | "0x01f0E453B85A9F411166d486Ab645ff720A47335" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /New Faucet/contracts/Faucet.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | import "./Libraries/SafeMath.sol"; 5 | 6 | /* 7 | * @title: Rinkeby Test Faucet [Modified]. 8 | * @author: Anthony (fps) https://github.com/0xfps. 9 | * @dev: 10 | * 11 | * I once wrote this contract to deposit any specific amount of ether from the contract. 12 | * But on this mod [28/05/2022] I am re-writing it to actually dispose some specific ether 0.2 ether. 13 | * But it shall demand just 1 ether for fundings. 14 | */ 15 | contract Faucet { 16 | // Use SafeMath for all uint. 17 | using SafeMath for uint256; 18 | // Faucet has no owner. 19 | // Collections, that is the total amount that a particular address has collected from the Faucet. 20 | mapping (address => uint256) private collections; 21 | // Funders, the total amount that a particular address has donated to the Faucet. 22 | mapping (address => uint256) private funders; 23 | // Time, the last time a particular address withdrew. Addresses can withdraw ether every 12 hours. 24 | mapping (address => uint256) private time; 25 | // Array of the addresses that have donated to the faucet. 26 | address[] public donators; 27 | // Balance of the contract. 28 | uint256 private balance; 29 | // Interval that is 12 hours. 30 | uint256 private interval = 12 hours; 31 | // uint256 private interval = 1 seconds; 32 | // Boolean to check for Re-Entrancy attacks. 33 | bool locked; 34 | 35 | // Emitted when someone funds the contract. 36 | event Fund(address indexed __funder, uint256 indexed __fund); 37 | // Emitted when the contract pays someone. 38 | event Pay(address indexed __receiver, uint256 indexed __fund); 39 | 40 | receive() external payable{} 41 | fallback() external payable{} 42 | 43 | // Checks for Re-Entrancy attacks. 44 | modifier noReEntrance() { 45 | // Requires that the locked is set to false. 46 | require(!locked, "No ReEntrance"); 47 | // Lock the function. 48 | locked = true; 49 | // Execute. 50 | _; 51 | // Re-open the lock. 52 | locked = false; 53 | } 54 | 55 | // Checks if the address is in the donators array for a new push. 56 | function hasDonated(address _address) private view returns(bool) { 57 | // Push the length of the donators array to memory. 58 | uint256 l = donators.length; 59 | 60 | // Loop over the array 61 | for (uint256 k = 0; k < l; k++) { 62 | // If the donor exists in the array. 63 | if (donators[k] == _address) 64 | // Return true. 65 | return true; 66 | } 67 | 68 | // On loop end, that is, the donor is not in the array. 69 | return false; 70 | } 71 | 72 | /* 73 | * @dev: 74 | * 75 | * Funds any address on the condition that the time span of the last transaction to that address was 12 hours. 76 | */ 77 | function fund() public payable noReEntrance { 78 | // Ensure address donating isn't a 0 address. 79 | require(msg.sender != address(0), "!Address"); 80 | // Require that the donation is >= 1 ether. 81 | require(msg.value >= 1 ether, "Amount needed: 1 ether"); 82 | // Balance left after donation. 83 | uint bal = msg.value - 1 ether; 84 | // This should be == 1 ether but for confirmation purposes. 85 | uint _fund = msg.value - bal; 86 | // Record the funders value; 87 | // (, uint256 j) = funders[msg.sender].tryAdd(1 ether); 88 | (, uint256 j) = funders[msg.sender].tryAdd(_fund); 89 | // Update the funder value. 90 | funders[msg.sender] = j; 91 | // Increment the balance of the contract. 92 | // (, uint256 p) = balance.tryAdd(1 ether); 93 | (, uint256 p) = balance.tryAdd(_fund); 94 | // Update new balance. 95 | balance = p; 96 | 97 | // If the address has not donated before, it should be added to the donators array. 98 | if (!hasDonated(msg.sender)) { 99 | // Add the address to the array. 100 | donators.push(msg.sender); 101 | } 102 | 103 | // Emit the fund event. 104 | emit Fund(msg.sender, _fund); 105 | 106 | // If the balance is > 0. 107 | if (bal > 0) { 108 | // Refund the balance`. 109 | payable(msg.sender).transfer(bal); 110 | // Emit the pay event. 111 | emit Pay(msg.sender, bal); 112 | } 113 | } 114 | 115 | /* 116 | * @dev: 117 | * 118 | * This function requests for some ether from the faucet. 119 | * The faucet dispenses 0.2 ether for every address every 12 hours. 120 | */ 121 | function request() public payable noReEntrance { 122 | // Ensure address donating isn't a 0 address. 123 | require(msg.sender != address(0), "!Address"); 124 | // Make sure that the contract still has ether. 125 | require(balance > 0, "We have run out of ether"); 126 | // Get the requester's last request time. 127 | uint256 last_time = time[msg.sender]; 128 | // Make sure that the time passed is more than or == 12 hours. 129 | require((block.timestamp - last_time) > interval, "You can only withdraw every 12 hours!"); 130 | // Remove 0.2 ether from balance. 131 | (, uint256 p) = balance.trySub(0.2 ether); 132 | // Reassign new balance. 133 | balance = p; 134 | // Update the collections of the requester. 135 | (, uint j) = collections[msg.sender].trySub(0.2 ether); 136 | // Update the requesters collections. 137 | collections[msg.sender] = j; 138 | // Update the last request time. 139 | time[msg.sender] = block.timestamp; 140 | // Transfer the funds to the requester. 141 | payable(msg.sender).transfer(0.2 ether); 142 | // Emit the pay event. 143 | emit Pay(msg.sender, 0.2 ether); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /New Faucet/contracts/Libraries/SafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | 5 | 6 | library SafeMath { 7 | /** 8 | * @dev Returns the addition of two unsigned integers, with an overflow flag. 9 | * 10 | * _Available since v3.4._ 11 | */ 12 | function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { 13 | unchecked { 14 | uint256 c = a + b; 15 | if (c < a) return (false, 0); 16 | return (true, c); 17 | } 18 | } 19 | 20 | /** 21 | * @dev Returns the subtraction of two unsigned integers, with an overflow flag. 22 | * 23 | * _Available since v3.4._ 24 | */ 25 | function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { 26 | unchecked { 27 | if (b > a) return (false, 0); 28 | return (true, a - b); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /New Faucet/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/New Faucet/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /New Faucet/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import Faucet, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract Faucet...") 8 | deploy_wallet = Faucet.deploy({"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "a+") as dep: 12 | dep.write("\n\nFaucet => "+deploy_wallet.address) 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # my-solidity 2 | My Solidity projects. 3 | 4 | ## **1. English auction for NFT.** 5 | 6 | > - Seller of NFT deploys this contract. 7 | > - Auction lasts for 7 days. 8 | > - Participants can bid by depositing ETH greater than the current highest bidder. 9 | > - All bidders can withdraw their bid if it is not the current highest bid. 10 | 11 |
12 | 13 | ## After the auction: 14 | 15 | > - Highest bidder becomes the new owner of NFT. 16 | > - The seller receives the highest bid of ETH. 17 | 18 | [Deployed contract on Rinkeby Etherscan.](https://rinkeby.etherscan.io/address/0x8816cd156792F4Fd9A081f14548D7Fa6040DfCf0) 19 | 20 | ### 21 | 22 |
23 | 24 | ## **2. Crowd Fund** 25 | 26 | **Crowd fund ERC20 token** 27 | 28 | > - User creates a campaign with a particular token. 29 | > - Users can pledge, transferring their token to a campaign. 30 | > - After the campaign ends, campaign creator can claim the funds if total amount pledged is more than the campaign goal. 31 | > - Otherwise, campaign did not reach it's goal, users can withdraw their pledge. 32 | 33 | [Deployed contract on Rinkeby Etherscan.](https://rinkeby.etherscan.io/address/0x579df29C056e4Bb9CD548EdEEB4b80CB4679b1Ec) 34 | 35 |
36 | 37 | ### 38 | 39 | ## **3. Dutch Auction** 40 | 41 | **Dutch auction for NFT** 42 | 43 | - Auction 44 | > - Seller of NFT deploys this contract setting a starting price for the NFT. 45 | > - Auction lasts for 7 days. 46 | > - Price of NFT decreases over time. 47 | > - Participants can buy by depositing ETH greater than the current price computed by the smart contract. 48 | > - Auction ends when a buyer buys the NFT. 49 | 50 | [Deployed contract on Rinkeby Etherscan.](https://rinkeby.etherscan.io/address/0x56aA4d97DA83b93372B6366482b929B86580452a) 51 | 52 | ### 53 | 54 |
55 | 56 | ## **4. Faucet** 57 | 58 | > - A simple Rinkeby Ethereum faucet that transfers 0.2 ether to addresses that request for it. 59 | > - Ether can be transferred to addresses as long as the interval is 12 hours. 60 | > - Faucet funders are recorded and are public. 61 | > - Faucet funders can only transfer 1 ether to the faucet. 62 | > - On any transfers of more than 1 ether, the balance is sent back to the funder, and 1 ether is taken in by the contract. 63 | 64 | [Deployed contract on Rinkeby Etherscan.](https://rinkeby.etherscan.io/address/0x196ca425A223C5325d63e7245C93a284B6D5EA3c) 65 | 66 | ### 67 | 68 |
69 | 70 | ## **5. Delegatecall** 71 | 72 | > - An upgradable smart contract project implementing the delegatecall functionality. 73 | > - It includes the 3 necessary contracts an upgradable contract should have. 74 | [x] [Proxy.sol](https://github.com/fps8k/my-solidity/blob/main/Delegatecall/Delegatecall%20Source/Proxy.sol): The contract to interact with the upgradable contract. 75 | [x] [Store.sol](https://github.com/fps8k/my-solidity/blob/main/Delegatecall/Delegatecall%20Source/Utils/Store.sol): The contract holding the storage variables. 76 | [x] [Main.sol](https://github.com/fps8k/my-solidity/blob/main/Delegatecall/Delegatecall%20Source/Utils/Main.sol): The actual contract that handles the logic. 77 | [ ] [Admin.sol](https://github.com/fps8k/my-solidity/blob/main/Delegatecall/Delegatecall%20Source/Utils/Admin.sol): Contract with admin roles. This is optional. 78 | 79 | [Proxy contract on Rinkeby Etherscan.](https://rinkeby.etherscan.io/address/0xDC4Ddd0324C86C7167ECc906b9FbF4a1055F40fa) 80 | 81 | ### 82 | 83 |
84 | 85 | ## **6. ERC-20 ($FPS)** 86 | 87 | > - ERC-20 Token. 88 | 89 | [Deployed contract on Rinkeby Etherscan.](https://rinkeby.etherscan.io/address/0x9af84a56B0b2444Fa2367C13862B652567CD0A1b) 90 | 91 | ### 92 | 93 |
94 | 95 | ## **7. New Faucet** 96 | 97 | > - Modified [Faucet](https://github.com/fps8k/my-solidity/tree/main/Faucet) contract. 98 | 99 | ### 100 | 101 |
102 | 103 | ## **8. USDT** 104 | 105 | > - $USDT, a copy of the ERC-20 token on Rinkeby USDT for token testings on development network. 106 | 107 | [Deployed contract on Rinkeby Etherscan.](https://rinkeby.etherscan.io/address/0x788b76Ee23FAa205F3d4991C9977618Cc7c6a019f3b5F7f319EDF7C)
108 | [Deployed contract on Rinkeby Etherscan.](https://rinkeby.etherscan.io/address/0x770861CdcdDF8319C6C86ef8EF91C4A922fc12aC) 109 | 110 | ### 111 | 112 |
113 | 114 | ## **9. Address Book** 115 | 116 | > - A basic contract that works like a phone book. Allowing users to map names to addresses, and retrieving it when needed. 117 | 118 | [Deployed contract on Rinkeby Etherscan.](https://rinkeby.etherscan.io/address/0x93a9b149A40490d03aA37de469105A8049932e30) 119 | 120 | ### 121 | 122 |
123 | 124 | ## **10. $AGU** 125 | 126 | > - ERC-20 Token. 127 | 128 | [Deployed contract on Rinkeby Etherscan (1).](https://rinkeby.etherscan.io/address/0x183A9aA20E1596669BD81EacCDCe17E6705449f5) 129 | [Deployed contract on Rinkeby Etherscan (2).](https://rinkeby.etherscan.io/address/0x2DFA0332E058c4FcC9d1b8C165eFf1CF52368d03) 130 | 131 | ### 132 | 133 |
134 | 135 | ## **11. $AGU 2** 136 | 137 | > - A modified [$AGU](https://github.com/fps8k/my-solidity/tree/main/erc20%20-%20%24AGU) 138 | 139 | ### 140 | 141 |
142 | 143 | ## **12. ERC-721** 144 | 145 | > - Legio, an ERC-721 NFT project. 146 | 147 | [Deployed contract on Rinkeby Etherscan (1).](https://rinkeby.etherscan.io/address/0x251568c2ba92a7CD30CF1f5a6c27dD42b167011A)
148 | [Deployed contract on Rinkeby Etherscan (2).](https://rinkeby.etherscan.io/address/0xbc71d1049d984f261663c3b46c1F443C622852EF)
149 | [Deployed contract on Rinkeby Etherscan (3).](https://rinkeby.etherscan.io/address/0xD17E6E1daB2d1E778278f5358ca68D572b713cdF) 150 | 151 | ### 152 | 153 |
154 | 155 | ## **13. Ether Wallet** 156 | 157 | > - EtherWallet, a crowdfunding smart contract. 158 | > - This is a simple Solidity program that allows anyone to send ether to a wallet then allowing only the owner to withdraw. 159 | > - This was my FIRST Solidity Smart Contract task, and I am so proud of it ❤🕊. 160 | 161 | [Deployed contract on Rinkeby Etherscan.](https://rinkeby.etherscan.io/address/0x72a8422a0E0098eF770A0dfdA312Ec1bd44fdB44) 162 | 163 | ### 164 | 165 |
166 | 167 | ## **14. Iterable Mapping** 168 | 169 | > - A contract that communicates between a mapping and an array stored on the contract. 170 | 171 | [Deployed contract on Rinkeby Etherscan.](https://rinkeby.etherscan.io/address/0x1A09e937AB84b5434a70aDaBC69b9884B85ED123d0d0EC2) 172 | 173 | ### 174 | 175 |
176 | 177 | ## **15. Libraries** 178 | 179 | > - A bunch of libraries I wrote for math, experimenting. 180 | 181 | ### 182 | 183 |
184 | 185 | ## **16. Liquidity** 186 | 187 | > - Uniswap's liquidity contracts I studied. 188 | 189 | ### 190 | 191 |
192 | 193 | ## **17. Merkle Tree** 194 | 195 | > - A contract that calculates the merkle tree from an array of transactions made with the contract. 196 | > - _Hint: I bugged this contract 😉._ 197 | 198 | [Deployed contract on Rinkeby Etherscan.](https://rinkeby.etherscan.io/address/0x7fF08E0dd90bBf3B22008fB1b28Bb4B037a8B79D) 199 | 200 | ### 201 | 202 |
203 | 204 | ## **18. Multi-Sig Wallet** 205 | 206 | > - A contract that approves pending transactions made on the contract on the condition that ((1/2) + 1) of the users of the contract has approved it. 207 | 208 | [Deployed contract on Rinkeby Etherscan.](https://rinkeby.etherscan.io/address/0x14C6Bb868EB71cAaDf19601699C760926511578F) 209 | 210 | ### 211 | 212 |
213 | 214 | ## **19. Token Task** 215 | 216 | ### 217 | 218 |
219 | 220 | ## **20. Sign.sol** 221 | 222 | A demo practise about signing and verifying signed transactions with Solidity. 223 | 224 | ### 225 | 226 |
227 | 228 | ## **21. StoreEmitAndRetrieve.sol** 229 | 230 | Simple storage and retrieval with Solidity. 231 | 232 | ### 233 | 234 |
235 | 236 | ## **22. Create2Factory** 237 | 238 | Practical contract applying the create 2 functionality to pre-calculate the deploy address of a particular contract with its constructor parameters and salt. 239 | -------------------------------------------------------------------------------- /Random/ExternalContractTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.14; 3 | 4 | contract ExternalContract { 5 | function returnMsgSender() external view returns(address) { 6 | return msg.sender; 7 | } 8 | } 9 | 10 | 11 | contract ExternalContractInheritor is ExternalContract { 12 | ExternalContract _externalContract; 13 | 14 | function deployExternalContract() public { 15 | _externalContract = new ExternalContract(); 16 | } 17 | 18 | function callExternalContractFuncton() external view returns(address) { 19 | return _externalContract.returnMsgSender(); 20 | } 21 | } 22 | 23 | 24 | contract ExternalContractImporter { 25 | ExternalContract _externalContract; 26 | 27 | function deployExternalContract() public { 28 | _externalContract = new ExternalContract(); 29 | } 30 | 31 | function callExternalContractFuncton() public view returns(address) { 32 | return _externalContract.returnMsgSender(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Sign.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.6.0; 3 | 4 | /* 5 | * @title: Signed Message. 6 | * @author: Anthony (fps) https://github.com/0xfps. 7 | * @dev: Sign and Verify Message. 8 | */ 9 | 10 | contract Signed { 11 | address public addr; 12 | 13 | function hashMessage() public pure returns(bytes32) { 14 | return(keccak256("I sent a transaction")); 15 | } 16 | 17 | function signMessage() public pure returns(bytes32) { 18 | return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hashMessage())); 19 | } 20 | 21 | function splitSignature(bytes32 sig) 22 | private 23 | pure 24 | returns( 25 | bytes32 r, 26 | bytes32 s, 27 | uint8 v 28 | ) 29 | { 30 | assembly { 31 | /* 32 | First 32 bytes stores the length of the signature 33 | 34 | add(sig, 32) = pointer of sig + 32 35 | effectively, skips first 32 bytes of signature 36 | 37 | mload(p) loads next 32 bytes starting at the memory address p into memory 38 | */ 39 | 40 | // first 32 bytes, after the length prefix 41 | r := mload(add(sig, 32)) 42 | // second 32 bytes 43 | s := mload(add(sig, 64)) 44 | // final byte (first byte of the next 32 bytes) 45 | v := byte(0, mload(add(sig, 96))) 46 | } 47 | } 48 | 49 | function verify() public { 50 | (bytes32 r, bytes32 s, uint8 v) = splitSignature(signMessage()); 51 | addr = ecrecover( 52 | hashMessage(), 53 | v, 54 | r, 55 | s 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /StoreEmitAndRetrieve.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.7; 3 | 4 | contract StoreEmitAndRetrieve { 5 | uint256 private _value; 6 | 7 | event NewValue(uint256 newValue); 8 | 9 | function store(uint256 newValue) public { 10 | _value = newValue; 11 | emit NewValue(newValue); 12 | } 13 | 14 | function retrieve() public view returns (uint256) { 15 | return _value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /USDT/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /USDT/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "USDT": [ 4 | "0x770861CdcdDF8319C6C86ef8EF91C4A922fc12aC", 5 | "0x788b76Ee23FAa205F3d4991C9977618Cc7c6a019" 6 | ] 7 | } 8 | } -------------------------------------------------------------------------------- /USDT/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/USDT/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /USDT/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import USDT, config, accounts, network 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract USDT...") 8 | deploy_wallet = USDT.deploy({"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "a+") as dep: 12 | dep.write("\n\nUSDT => "+deploy_wallet.address) 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /bytecode.json: -------------------------------------------------------------------------------- 1 | { 2 | "functionDebugData": {}, 3 | "generatedSources": [], 4 | "linkReferences": {}, 5 | "object": "608060405234801561001057600080fd5b50610242806100206000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c806343fe79ec1461005157806349068a8914610086578063767800de1461008e578063fc735e99146100b9575b600080fd5b7ff76b1604ca1623f20b516bc9709123b3898833f93146186036adbdaeda9ed5d65b6040519081526020015b60405180910390f35b6100736100c3565b6000546100a1906001600160a01b031681565b6040516001600160a01b03909116815260200161007d565b6100c1610135565b005b60007ff76b1604ca1623f20b516bc9709123b3898833f93146186036adbdaeda9ed5d66040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c810191909152605c0160405160208183030381529060405280519060200120905090565b60008060006101606101456100c3565b60208101516040820151606090920151909260009190911a90565b925092509250600161018f7ff76b1604ca1623f20b516bc9709123b3898833f93146186036adbdaeda9ed5d690565b6040805160008152602081018083529290925260ff841690820152606081018590526080810184905260a0016020604051602081039080840390855afa1580156101dd573d6000803e3d6000fd5b5050604051601f190151600080546001600160a01b0319166001600160a01b039092169190911790555050505056fea26469706673582212209cb574bb4efe8fa76d4edf509c081589b46d2a4cfcfe4df4de23fe151c28ea0464736f6c63430008070033", 6 | "opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x242 DUP1 PUSH2 0x20 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH2 0x4C JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x43FE79EC EQ PUSH2 0x51 JUMPI DUP1 PUSH4 0x49068A89 EQ PUSH2 0x86 JUMPI DUP1 PUSH4 0x767800DE EQ PUSH2 0x8E JUMPI DUP1 PUSH4 0xFC735E99 EQ PUSH2 0xB9 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH32 0xF76B1604CA1623F20B516BC9709123B3898833F93146186036ADBDAEDA9ED5D6 JUMPDEST PUSH1 0x40 MLOAD SWAP1 DUP2 MSTORE PUSH1 0x20 ADD JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0x73 PUSH2 0xC3 JUMP JUMPDEST PUSH1 0x0 SLOAD PUSH2 0xA1 SWAP1 PUSH1 0x1 PUSH1 0x1 PUSH1 0xA0 SHL SUB AND DUP2 JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH1 0x1 PUSH1 0x1 PUSH1 0xA0 SHL SUB SWAP1 SWAP2 AND DUP2 MSTORE PUSH1 0x20 ADD PUSH2 0x7D JUMP JUMPDEST PUSH2 0xC1 PUSH2 0x135 JUMP JUMPDEST STOP JUMPDEST PUSH1 0x0 PUSH32 0xF76B1604CA1623F20B516BC9709123B3898833F93146186036ADBDAEDA9ED5D6 PUSH1 0x40 MLOAD PUSH32 0x19457468657265756D205369676E6564204D6573736167653A0A333200000000 PUSH1 0x20 DUP3 ADD MSTORE PUSH1 0x3C DUP2 ADD SWAP2 SWAP1 SWAP2 MSTORE PUSH1 0x5C ADD PUSH1 0x40 MLOAD PUSH1 0x20 DUP2 DUP4 SUB SUB DUP2 MSTORE SWAP1 PUSH1 0x40 MSTORE DUP1 MLOAD SWAP1 PUSH1 0x20 ADD KECCAK256 SWAP1 POP SWAP1 JUMP JUMPDEST PUSH1 0x0 DUP1 PUSH1 0x0 PUSH2 0x160 PUSH2 0x145 PUSH2 0xC3 JUMP JUMPDEST PUSH1 0x20 DUP2 ADD MLOAD PUSH1 0x40 DUP3 ADD MLOAD PUSH1 0x60 SWAP1 SWAP3 ADD MLOAD SWAP1 SWAP3 PUSH1 0x0 SWAP2 SWAP1 SWAP2 BYTE SWAP1 JUMP JUMPDEST SWAP3 POP SWAP3 POP SWAP3 POP PUSH1 0x1 PUSH2 0x18F PUSH32 0xF76B1604CA1623F20B516BC9709123B3898833F93146186036ADBDAEDA9ED5D6 SWAP1 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD PUSH1 0x0 DUP2 MSTORE PUSH1 0x20 DUP2 ADD DUP1 DUP4 MSTORE SWAP3 SWAP1 SWAP3 MSTORE PUSH1 0xFF DUP5 AND SWAP1 DUP3 ADD MSTORE PUSH1 0x60 DUP2 ADD DUP6 SWAP1 MSTORE PUSH1 0x80 DUP2 ADD DUP5 SWAP1 MSTORE PUSH1 0xA0 ADD PUSH1 0x20 PUSH1 0x40 MLOAD PUSH1 0x20 DUP2 SUB SWAP1 DUP1 DUP5 SUB SWAP1 DUP6 GAS STATICCALL ISZERO DUP1 ISZERO PUSH2 0x1DD JUMPI RETURNDATASIZE PUSH1 0x0 DUP1 RETURNDATACOPY RETURNDATASIZE PUSH1 0x0 REVERT JUMPDEST POP POP PUSH1 0x40 MLOAD PUSH1 0x1F NOT ADD MLOAD PUSH1 0x0 DUP1 SLOAD PUSH1 0x1 PUSH1 0x1 PUSH1 0xA0 SHL SUB NOT AND PUSH1 0x1 PUSH1 0x1 PUSH1 0xA0 SHL SUB SWAP1 SWAP3 AND SWAP2 SWAP1 SWAP2 OR SWAP1 SSTORE POP POP POP POP JUMP INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 SWAP13 0xB5 PUSH21 0xBB4EFE8FA76D4EDF509C081589B46D2A4CFCFE4DF4 0xDE 0x23 INVALID ISZERO SHR 0x28 0xEA DIV PUSH5 0x736F6C6343 STOP ADDMOD SMOD STOP CALLER ", 7 | "sourceMap": "146:1225:0:-:0;;;;;;;;;;;;;;;;;;;" 8 | } -------------------------------------------------------------------------------- /deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import MyAuction, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract MyAuction...") 8 | deploy_wallet = MyAuction.deploy({"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "a+") as dep: 12 | dep.write("\n\nMyAuction => "+deploy_wallet.address) 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /deployed AddressBook/AddressBook/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /deployed AddressBook/AddressBook/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "AddressBook": [ 4 | "0x93a9b149A40490d03aA37de469105A8049932e30", 5 | "0x75827B81FE1D617553008D468184F6dB51B551A9", 6 | "0x4d6fa467d387bE828003f817bAb623526f027485", 7 | "0x395E24d23c52537B312373B53EbaF76259fCAB33", 8 | "0x51aa609240582C2Cf6B62dEf911FBbC6620641c5" 9 | ] 10 | } 11 | } -------------------------------------------------------------------------------- /deployed AddressBook/AddressBook/build/tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "contracts": { 3 | "AddressBook": "66b98dbdea4817ef97be43de9c245427303bead0" 4 | }, 5 | "tests": { 6 | "tests/test_addressbook.py": { 7 | "coverage": false, 8 | "isolated": false, 9 | "results": "....", 10 | "sha1": "0ab8a4739a11e203485eaa501d8c9b9472625261", 11 | "txhash": [] 12 | } 13 | }, 14 | "tx": {} 15 | } -------------------------------------------------------------------------------- /deployed AddressBook/AddressBook/contracts/AddressBook.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | /* 5 | * @title: AddressBook contract. 6 | * @author: Anthony (fps) https://github.com/0xfps. 7 | * @dev: 8 | */ 9 | contract AddressBook { 10 | // Mapping the name to the addresses. 11 | mapping(address => mapping(string => address)) private book; 12 | 13 | // Events. 14 | event Add(string, address); // Name, Address. 15 | event Remove(string, address); // Name, Address. 16 | event ChangeName(string, string, address); // Old name, New name, Old address, New address. 17 | event ChangeAddress(string, address, address); // Old name, New name, Old address, New address. 18 | 19 | modifier isValidSender() { 20 | require(msg.sender != address(0), "!Address"); 21 | _; 22 | } 23 | 24 | function exists(string memory _search) private view returns(bool) { 25 | return book[msg.sender][_search] != address(0); 26 | // Returns true if the name is saved. 27 | } 28 | 29 | function add(string memory _name, address _address) public isValidSender { 30 | require(bytes(_name).length > 0, "Empty"); 31 | require(_address != address(0), "!Address"); 32 | require(!exists(_name), "Name Exists"); 33 | book[msg.sender][_name] = _address; 34 | emit Add(_name, _address); 35 | } 36 | 37 | function remove(string memory _name) public isValidSender { 38 | require(bytes(_name).length > 0, "Empty"); 39 | require(exists(_name), "Name !Exists"); 40 | address _address = book[msg.sender][_name]; 41 | delete book[msg.sender][_name]; 42 | emit Remove(_name, _address); 43 | } 44 | 45 | function updateAddress(string memory _name, address _address) public isValidSender { 46 | require(bytes(_name).length > 0, "Empty"); 47 | require(_address != address(0), "!Address"); 48 | require(!exists(_name), "Name Exists"); 49 | address old_address = book[msg.sender][_name]; 50 | book[msg.sender][_name] = _address; 51 | emit ChangeAddress(_name, old_address, _address); 52 | } 53 | 54 | function updateName(string memory _name, string memory new_name) public isValidSender { 55 | require(bytes(_name).length > 0, "Empty"); 56 | require(bytes(new_name).length > 0, "New Name Empty"); 57 | require(exists(_name), "Name !Exists"); 58 | require(!exists(new_name), "New Name Exists"); 59 | address _address = book[msg.sender][_name]; 60 | book[msg.sender][new_name] = _address; 61 | delete book[msg.sender][_name]; 62 | emit ChangeName(_name, new_name, _address); 63 | } 64 | 65 | function getAddress(string memory _name) public view isValidSender returns(address) { 66 | require(bytes(_name).length > 0, "Empty"); 67 | require(exists(_name), "Name !Exists"); 68 | return book[msg.sender][_name]; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /deployed AddressBook/AddressBook/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/deployed AddressBook/AddressBook/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /deployed AddressBook/AddressBook/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import AddressBook, config, network, accounts 2 | 3 | def deploy(): 4 | account = getAccount() 5 | 6 | print("Deploying...") 7 | 8 | deploy = AddressBook.deploy({"from": account}, publish_source=True) 9 | 10 | 11 | print(f"Deployed at {deploy.address} !!!") 12 | 13 | title = "AddressBook" 14 | link = "https://rinkeby.etherscan.io/address/" 15 | with open("../Deployment Address.txt", "a+") as file: 16 | file.write(f"{title} => {link}{deploy.address}\n\n") 17 | 18 | 19 | def getAccount(): 20 | if network.show_active() == "development": 21 | return accounts[0] 22 | else: 23 | return accounts.add(config['wallet']['from_key']) 24 | 25 | def main(): 26 | deploy() -------------------------------------------------------------------------------- /deployed AddressBook/AddressBook/tests/__pycache__/test_addressbook.cpython-310-pytest-6.2.5.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/deployed AddressBook/AddressBook/tests/__pycache__/test_addressbook.cpython-310-pytest-6.2.5.pyc -------------------------------------------------------------------------------- /deployed AddressBook/AddressBook/tests/test_addressbook.py: -------------------------------------------------------------------------------- 1 | from brownie import AddressBook, config, network, accounts, reverts 2 | 3 | def testDeploy(): 4 | ## Arrange. 5 | print("Starting test...") 6 | account = accounts[0] 7 | 8 | ## Actions. 9 | deploy_var = AddressBook.deploy({"from": account}) 10 | _zero_address = "0x0000000000000000000000000000000000000000" 11 | 12 | ## Assert. 13 | assert deploy_var.address != _zero_address 14 | 15 | 16 | def testAdd(): 17 | ## Arrange. 18 | print("Starting test...") 19 | account = accounts[0] 20 | 21 | ## Actions. 22 | deploy_var = AddressBook.deploy({"from": account}) 23 | deploy_var.add("fps", "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593", {"from": account}) 24 | 25 | _zero_address = "0x0000000000000000000000000000000000000000" 26 | 27 | act_address = _zero_address 28 | 29 | with reverts(): 30 | act_address = deploy_var.getAddress("Act") 31 | 32 | expected_fps_address = "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593" 33 | actual_fps_address = deploy_var.getAddress("fps") 34 | 35 | ## Assert. 36 | assert act_address == _zero_address 37 | assert expected_fps_address == actual_fps_address 38 | 39 | 40 | 41 | def testRename(): 42 | account = accounts[0] 43 | 44 | deploy_var = AddressBook.deploy({"from": account}) 45 | 46 | deploy_var.add("fps", "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593", {"from": account}) 47 | 48 | deploy_var.updateName("fps", "solo", {"from": account}) 49 | 50 | _zero_address = "0x0000000000000000000000000000000000000000" 51 | expected_address = "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593" 52 | fake_address = _zero_address 53 | 54 | with reverts(): 55 | fake_address = deploy_var.getAddress("fps") 56 | 57 | actual_address = deploy_var.getAddress("solo") 58 | 59 | assert fake_address == _zero_address 60 | assert actual_address == expected_address 61 | 62 | 63 | 64 | def testDelete(): 65 | account = accounts[0] 66 | 67 | deploy_var = AddressBook.deploy({"from": account}) 68 | 69 | deploy_var.add("fps", "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593", {"from": account}) 70 | 71 | deploy_var.updateName("fps", "solo", {"from": account}) 72 | 73 | deploy_var.remove("solo", {"from": account}) 74 | 75 | _zero_address = "0x0000000000000000000000000000000000000000" 76 | expected_address = "0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593" 77 | fake_address = _zero_address 78 | actual_address = _zero_address 79 | 80 | with reverts(): 81 | fake_address = deploy_var.getAddress("fps") 82 | actual_address = deploy_var.getAddress("solo") 83 | 84 | assert fake_address == _zero_address 85 | assert actual_address != expected_address -------------------------------------------------------------------------------- /deployed AddressBook/Deployment Address.txt: -------------------------------------------------------------------------------- 1 | AddressBook => https://rinkeby.etherscan.io/address/0x93a9b149A40490d03aA37de469105A8049932e30 2 | 3 | -------------------------------------------------------------------------------- /erc20 - $AGU 2/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /erc20 - $AGU 2/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "Aguia": [ 4 | "0x183A9aA20E1596669BD81EacCDCe17E6705449f5" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /erc20 - $AGU 2/contracts/Interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Interface of the ERC20 standard as defined in the EIP. 8 | */ 9 | interface IERC20 { 10 | /** 11 | * @dev Returns the amount of tokens in existence. 12 | */ 13 | function totalSupply() external view returns (uint256); 14 | 15 | /** 16 | * @dev Returns the amount of tokens owned by `account`. 17 | */ 18 | function balanceOf(address account) external view returns (uint256); 19 | 20 | /** 21 | * @dev Moves `amount` tokens from the caller's account to `to`. 22 | * 23 | * Returns a boolean value indicating whether the operation succeeded. 24 | * 25 | * Emits a {Transfer} event. 26 | */ 27 | function transfer(address to, uint256 amount) external returns (bool); 28 | 29 | /** 30 | * @dev Returns the remaining number of tokens that `spender` will be 31 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 32 | * zero by default. 33 | * 34 | * This value changes when {approve} or {transferFrom} are called. 35 | */ 36 | function allowance(address owner, address spender) external view returns (uint256); 37 | 38 | /** 39 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 40 | * 41 | * Returns a boolean value indicating whether the operation succeeded. 42 | * 43 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 44 | * that someone may use both the old and the new allowance by unfortunate 45 | * transaction ordering. One possible solution to mitigate this race 46 | * condition is to first reduce the spender's allowance to 0 and set the 47 | * desired value afterwards: 48 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 49 | * 50 | * Emits an {Approval} event. 51 | */ 52 | function approve(address spender, uint256 amount) external returns (bool); 53 | 54 | /** 55 | * @dev Moves `amount` tokens from `from` to `to` using the 56 | * allowance mechanism. `amount` is then deducted from the caller's 57 | * allowance. 58 | * 59 | * Returns a boolean value indicating whether the operation succeeded. 60 | * 61 | * Emits a {Transfer} event. 62 | */ 63 | function transferFrom( 64 | address from, 65 | address to, 66 | uint256 amount 67 | ) external returns (bool); 68 | 69 | /** 70 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 71 | * another (`to`). 72 | * 73 | * Note that `value` may be zero. 74 | */ 75 | event Transfer(address indexed from, address indexed to, uint256 value); 76 | 77 | /** 78 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 79 | * a call to {approve}. `value` is the new allowance. 80 | */ 81 | event Approval(address indexed owner, address indexed spender, uint256 value); 82 | } -------------------------------------------------------------------------------- /erc20 - $AGU 2/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/erc20 - $AGU 2/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /erc20 - $AGU 2/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import Aguia, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract Aguia...") 8 | deploy_wallet = Aguia.deploy({"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "a+") as dep: 12 | dep.write("\n\nAguia => https://rinkeby.etherscan.io/address/"+deploy_wallet.address) 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /erc20 - $AGU/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /erc20 - $AGU/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "AGU": [ 4 | "0x2DFA0332E058c4FcC9d1b8C165eFf1CF52368d03" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /erc20 - $AGU/contracts/Aguia.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | import "./IERC20.sol"; 5 | 6 | /* 7 | * @title: $AGU, an ERC-20 standard token. 8 | * @author: Anthony (fps) https://github.com/0xfps. 9 | * @date: 21/03/2022. 10 | * 11 | * @notice: This token, $AGU, obeys the standard of the ERC-20, created as my debut token. 12 | * Also, currently, I do not seem to understand the concept of the allowance, approve and transferFrom functions but 13 | * I hope Reddit comes to my aid. 14 | * 15 | * I M P O R T A N T : 16 | * '{text}' => Implies text is a data type. 17 | * `{text}` => Implies text is a variable name. 18 | * 19 | * T L D R : 20 | * 'data_type' 21 | * `variable_name` 22 | */ 23 | contract AGU is IERC20 { 24 | // @dev: Sets and allocates some tokens as `balances` to `addresses`. 25 | // Also creates an allowance between the 'address' {`_owner`} and 'address' {`spender`} to a particular 'uint' `allowance` 26 | mapping (address => uint) private balances; 27 | mapping (address => mapping (address => uint)) private _allowance; 28 | // @dev: Setting a 1 million total supply of the $AGU token and the decimal. 29 | uint256 private _totalSupply; 30 | uint8 private _decimal; 31 | // @dev: Setting token name and symbol. 32 | string private _name; 33 | string private _symbol; 34 | address constant _owner = 0x5e078E6b545cF88aBD5BB58d27488eF8BE0D2593; 35 | 36 | /* 37 | * @dev: Constructor 38 | */ 39 | constructor() { 40 | _name = "Aguia"; 41 | _symbol = "$AGU"; 42 | // total supply is 1 million plus the 3 decimal zeros 43 | _totalSupply = 1000000000; 44 | _decimal = 3; 45 | // address _owner = msg.sender; 46 | // get the _owner of the contract and assign to him all the funds 47 | // balances[msg.sender] = _totalSupply; 48 | // allocate all to me 49 | balances[_owner] = _totalSupply; 50 | } 51 | 52 | /* 53 | * @dev: `name()` function returns the name of the token 54 | */ 55 | function name() public view returns(string memory) { 56 | return _name; 57 | } 58 | 59 | /* 60 | * @dev: `symbol()` function returns the token symbol 61 | */ 62 | function symbol() public view returns(string memory) { 63 | return _symbol; 64 | } 65 | 66 | /* 67 | * @dev: `decimals()` function returns the token decimals 68 | */ 69 | function decimals() public view returns(uint8) { 70 | return _decimal; 71 | } 72 | 73 | /* 74 | * @notice: Implementation of functions necessary according to the ERC-20 standard. 75 | * Function 1: 76 | * 77 | * @dev: `totalSupply()` function returns the total number of token coins in existence 78 | */ 79 | function totalSupply() public view virtual override returns(uint) { 80 | return _totalSupply; 81 | } 82 | 83 | /* 84 | * @notice: Function 2: 85 | * 86 | * @dev: `balanceOf()` function: Returns the amount of token owned by a particular `account` 87 | */ 88 | function balanceOf(address account) public view virtual override returns (uint) { 89 | return balances[account]; 90 | } 91 | 92 | /* 93 | * @notice: Function 3: 94 | * 95 | * @dev: `transfer()` function: Transfers some token `amount` to a particular account of 'address', `to`, from the callers account 96 | * -- increments the `balances` of `to` by `amount` 97 | * -- decrements the `balances` of `msg.sender` by `amount` 98 | * 99 | * Returns a boolean that shows that it worked 100 | * 101 | * Emits a {Transfer} event 102 | * 103 | * @notice: This function is controlled by a modifier `canSend()` that makes sure that the sender has enough token in his account to send 104 | */ 105 | modifier canSend( 106 | address from, 107 | address to, 108 | uint amount 109 | ) 110 | { 111 | require(from != address(0), "You cannot transfer from an invalid address."); 112 | require(to != address(0), "You cannot transfer to an invalid address."); 113 | require(amount != 0, "You cannot send 0 $AGU."); 114 | require(balances[from] >= amount, "You do not have enough $AGU Coins to make this transaction."); 115 | _; 116 | } 117 | 118 | function transfer(address to, uint amount) 119 | public 120 | virtual 121 | override 122 | canSend( 123 | msg.sender, 124 | to, 125 | amount 126 | ) 127 | returns(bool) 128 | { 129 | balances[to] += amount; 130 | balances[msg.sender] -= amount; 131 | emit Transfer(msg.sender, to, amount); 132 | return true; 133 | } 134 | 135 | /* 136 | * @notice: Function 4: 137 | * @dev: `approve()` Sets `amount` as the allowance of `spender` over the caller's tokens. 138 | * Emits an {Approval} event. 139 | * 140 | * This is protected by a modifier 141 | */ 142 | modifier canApprove(address spender, uint amount) { 143 | require(spender != address(0), "You cannot request from an invalid address."); 144 | require(amount > 0, "You can't request for empty allowance."); 145 | require(balances[_owner] > amount, "Cannot approve alowance."); 146 | require(_allowance[_owner][spender] + amount < 100, "Allowance limit reached"); 147 | require(amount <= 100, "Allowance limit is 100."); 148 | _; 149 | } 150 | 151 | function approve(address spender, uint amount) 152 | public 153 | virtual 154 | override 155 | canApprove(spender, amount) 156 | returns(bool) 157 | { 158 | _allowance[_owner][spender] += amount; 159 | emit Approval(_owner, spender, amount); 160 | return true; 161 | } 162 | 163 | /* 164 | * @notice: Function 5: 165 | * @dev: `transferFrom()` Moves `amount` tokens from `from` to `to` using the 166 | * allowance mechanism. `amount` is then deducted from the caller's 167 | * allowance. 168 | * 169 | * Returns a boolean value indicating whether the operation succeeded. 170 | * 171 | * Emits a {Transfer} event. 172 | * 173 | * This is controlled by a modifier. 174 | */ 175 | modifier canTransfer( 176 | address from, 177 | address to, 178 | uint amount 179 | ) 180 | { 181 | require(_allowance[_owner][from] > amount, "You do not have enough allowance"); 182 | require(to != address(0), "You cannot transfer to an invalid address."); 183 | require(amount != 0, "You cannot send 0 $AGU."); 184 | _; 185 | } 186 | 187 | function transferFrom( 188 | address from, 189 | address to, 190 | uint256 amount 191 | ) 192 | public 193 | virtual 194 | override 195 | canTransfer( 196 | msg.sender, 197 | to, 198 | amount 199 | ) 200 | returns(bool) 201 | { 202 | from = msg.sender; 203 | balances[to] += amount; 204 | _allowance[_owner][from] -= amount; 205 | emit Transfer(from, to, amount); 206 | return true; 207 | } 208 | 209 | /* 210 | * @notice: Function 6: 211 | * @dev: `allowance()` Returns the remaining number of tokens that `spender` will be 212 | * allowed to spend on behalf of `_owner` through {transferFrom}. This is 213 | * zero by default. 214 | * 215 | * This value changes when {approve} or {transferFrom} are called. 216 | */ 217 | function allowance(address owner, address spender) 218 | public 219 | view 220 | virtual 221 | override 222 | returns (uint256) 223 | { 224 | owner = _owner; 225 | return (_allowance[owner][spender]); 226 | } 227 | 228 | /* 229 | * @notice: MINT 230 | * this function mints more tokens 231 | */ 232 | modifier onlyOwner() { 233 | require(msg.sender == _owner, "You cannot mint more of this token."); 234 | _; 235 | } 236 | 237 | function mint(uint amount) public onlyOwner returns(bool) { 238 | _totalSupply += amount; 239 | balances[_owner] += amount; 240 | return true; 241 | } 242 | 243 | function burn(uint amount) public onlyOwner returns(bool) { 244 | _totalSupply -= amount; 245 | balances[_owner] -= amount; 246 | return true; 247 | } 248 | } 249 | -------------------------------------------------------------------------------- /erc20 - $AGU/contracts/Context.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Provides information about the current execution context, including the 8 | * sender of the transaction and its data. While these are generally available 9 | * via msg.sender and msg.data, they should not be accessed in such a direct 10 | * manner, since when dealing with meta-transactions the account sending and 11 | * paying for execution may not be the actual sender (as far as an application 12 | * is concerned). 13 | * 14 | * This contract is only required for intermediate, library-like contracts. 15 | */ 16 | abstract contract Context { 17 | function _msgSender() internal view virtual returns (address) { 18 | return msg.sender; 19 | } 20 | 21 | function _msgData() internal view virtual returns (bytes calldata) { 22 | return msg.data; 23 | } 24 | } -------------------------------------------------------------------------------- /erc20 - $AGU/contracts/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Interface of the ERC20 standard as defined in the EIP. 8 | */ 9 | interface IERC20 { 10 | /** 11 | * @dev Returns the amount of tokens in existence. 12 | */ 13 | function totalSupply() external view returns (uint256); 14 | 15 | /** 16 | * @dev Returns the amount of tokens owned by `account`. 17 | */ 18 | function balanceOf(address account) external view returns (uint256); 19 | 20 | /** 21 | * @dev Moves `amount` tokens from the caller's account to `to`. 22 | * 23 | * Returns a boolean value indicating whether the operation succeeded. 24 | * 25 | * Emits a {Transfer} event. 26 | */ 27 | function transfer(address to, uint256 amount) external returns (bool); 28 | 29 | /** 30 | * @dev Returns the remaining number of tokens that `spender` will be 31 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 32 | * zero by default. 33 | * 34 | * This value changes when {approve} or {transferFrom} are called. 35 | */ 36 | function allowance(address owner, address spender) external view returns (uint256); 37 | 38 | /** 39 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 40 | * 41 | * Returns a boolean value indicating whether the operation succeeded. 42 | * 43 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 44 | * that someone may use both the old and the new allowance by unfortunate 45 | * transaction ordering. One possible solution to mitigate this race 46 | * condition is to first reduce the spender's allowance to 0 and set the 47 | * desired value afterwards: 48 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 49 | * 50 | * Emits an {Approval} event. 51 | */ 52 | function approve(address spender, uint256 amount) external returns (bool); 53 | 54 | /** 55 | * @dev Moves `amount` tokens from `from` to `to` using the 56 | * allowance mechanism. `amount` is then deducted from the caller's 57 | * allowance. 58 | * 59 | * Returns a boolean value indicating whether the operation succeeded. 60 | * 61 | * Emits a {Transfer} event. 62 | */ 63 | function transferFrom( 64 | address from, 65 | address to, 66 | uint256 amount 67 | ) external returns (bool); 68 | 69 | /** 70 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 71 | * another (`to`). 72 | * 73 | * Note that `value` may be zero. 74 | */ 75 | event Transfer(address indexed from, address indexed to, uint256 value); 76 | 77 | /** 78 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 79 | * a call to {approve}. `value` is the new allowance. 80 | */ 81 | event Approval(address indexed owner, address indexed spender, uint256 value); 82 | } -------------------------------------------------------------------------------- /erc20 - $AGU/contracts/IERC20Metadata.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./IERC20.sol"; 7 | 8 | /** 9 | * @dev Interface for the optional metadata functions from the ERC20 standard. 10 | * 11 | * _Available since v4.1._ 12 | */ 13 | interface IERC20Metadata is IERC20 { 14 | /** 15 | * @dev Returns the name of the token. 16 | */ 17 | function name() external view returns (string memory); 18 | 19 | /** 20 | * @dev Returns the symbol of the token. 21 | */ 22 | function symbol() external view returns (string memory); 23 | 24 | /** 25 | * @dev Returns the decimals places of the token. 26 | */ 27 | function decimals() external view returns (uint8); 28 | } -------------------------------------------------------------------------------- /erc20 - $AGU/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/erc20 - $AGU/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /erc20 - $AGU/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import AGU, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract EtherWallet...") 8 | deploy_wallet = AGU.deploy({"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "r+") as dep: 12 | dep.write("AGU => https://rinkeby.etherscan.io/address/"+deploy_wallet.address+"\n\n") 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /erc721/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /erc721/build/contracts/IERC165.json: -------------------------------------------------------------------------------- 1 | { 2 | "abi": [ 3 | { 4 | "inputs": [ 5 | { 6 | "internalType": "bytes4", 7 | "name": "interfaceId", 8 | "type": "bytes4" 9 | } 10 | ], 11 | "name": "supportsInterface", 12 | "outputs": [ 13 | { 14 | "internalType": "bool", 15 | "name": "", 16 | "type": "bool" 17 | } 18 | ], 19 | "stateMutability": "view", 20 | "type": "function" 21 | } 22 | ], 23 | "allSourcePaths": { 24 | "0": "contracts/interfaces/IERC165.sol" 25 | }, 26 | "ast": { 27 | "absolutePath": "contracts/interfaces/IERC165.sol", 28 | "exportedSymbols": { 29 | "IERC165": [ 30 | 686 31 | ] 32 | }, 33 | "id": 687, 34 | "license": "MIT", 35 | "nodeType": "SourceUnit", 36 | "nodes": [ 37 | { 38 | "id": 676, 39 | "literals": [ 40 | "solidity", 41 | ">", 42 | "0.6", 43 | ".0" 44 | ], 45 | "nodeType": "PragmaDirective", 46 | "src": "103:23:0" 47 | }, 48 | { 49 | "abstract": false, 50 | "baseContracts": [], 51 | "canonicalName": "IERC165", 52 | "contractDependencies": [], 53 | "contractKind": "interface", 54 | "documentation": { 55 | "id": 677, 56 | "nodeType": "StructuredDocumentation", 57 | "src": "130:287:0", 58 | "text": " @dev Interface of the ERC165 standard, as defined in the\n https://eips.ethereum.org/EIPS/eip-165[EIP].\n Implementers can declare support of contract interfaces, which can then be\n queried by others ({ERC165Checker}).\n For an implementation, see {ERC165}." 59 | }, 60 | "fullyImplemented": false, 61 | "id": 686, 62 | "linearizedBaseContracts": [ 63 | 686 64 | ], 65 | "name": "IERC165", 66 | "nameLocation": "429:7:0", 67 | "nodeType": "ContractDefinition", 68 | "nodes": [ 69 | { 70 | "documentation": { 71 | "id": 678, 72 | "nodeType": "StructuredDocumentation", 73 | "src": "444:347:0", 74 | "text": " @dev Returns true if this contract implements the interface defined by\n `interfaceId`. See the corresponding\n https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n to learn more about how these ids are created.\n This function call must use less than 30 000 gas." 75 | }, 76 | "functionSelector": "01ffc9a7", 77 | "id": 685, 78 | "implemented": false, 79 | "kind": "function", 80 | "modifiers": [], 81 | "name": "supportsInterface", 82 | "nameLocation": "806:17:0", 83 | "nodeType": "FunctionDefinition", 84 | "parameters": { 85 | "id": 681, 86 | "nodeType": "ParameterList", 87 | "parameters": [ 88 | { 89 | "constant": false, 90 | "id": 680, 91 | "mutability": "mutable", 92 | "name": "interfaceId", 93 | "nameLocation": "831:11:0", 94 | "nodeType": "VariableDeclaration", 95 | "scope": 685, 96 | "src": "824:18:0", 97 | "stateVariable": false, 98 | "storageLocation": "default", 99 | "typeDescriptions": { 100 | "typeIdentifier": "t_bytes4", 101 | "typeString": "bytes4" 102 | }, 103 | "typeName": { 104 | "id": 679, 105 | "name": "bytes4", 106 | "nodeType": "ElementaryTypeName", 107 | "src": "824:6:0", 108 | "typeDescriptions": { 109 | "typeIdentifier": "t_bytes4", 110 | "typeString": "bytes4" 111 | } 112 | }, 113 | "visibility": "internal" 114 | } 115 | ], 116 | "src": "823:20:0" 117 | }, 118 | "returnParameters": { 119 | "id": 684, 120 | "nodeType": "ParameterList", 121 | "parameters": [ 122 | { 123 | "constant": false, 124 | "id": 683, 125 | "mutability": "mutable", 126 | "name": "", 127 | "nameLocation": "-1:-1:-1", 128 | "nodeType": "VariableDeclaration", 129 | "scope": 685, 130 | "src": "867:4:0", 131 | "stateVariable": false, 132 | "storageLocation": "default", 133 | "typeDescriptions": { 134 | "typeIdentifier": "t_bool", 135 | "typeString": "bool" 136 | }, 137 | "typeName": { 138 | "id": 682, 139 | "name": "bool", 140 | "nodeType": "ElementaryTypeName", 141 | "src": "867:4:0", 142 | "typeDescriptions": { 143 | "typeIdentifier": "t_bool", 144 | "typeString": "bool" 145 | } 146 | }, 147 | "visibility": "internal" 148 | } 149 | ], 150 | "src": "866:6:0" 151 | }, 152 | "scope": 686, 153 | "src": "797:76:0", 154 | "stateMutability": "view", 155 | "virtual": false, 156 | "visibility": "external" 157 | } 158 | ], 159 | "scope": 687, 160 | "src": "419:457:0", 161 | "usedErrors": [] 162 | } 163 | ], 164 | "src": "103:773:0" 165 | }, 166 | "bytecode": "", 167 | "bytecodeSha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709", 168 | "compiler": { 169 | "evm_version": "istanbul", 170 | "optimizer": { 171 | "enabled": true, 172 | "runs": 200 173 | }, 174 | "version": "0.8.12+commit.f00d7308" 175 | }, 176 | "contractName": "IERC165", 177 | "coverageMap": { 178 | "branches": {}, 179 | "statements": {} 180 | }, 181 | "dependencies": [], 182 | "deployedBytecode": "", 183 | "deployedSourceMap": "", 184 | "language": "Solidity", 185 | "natspec": { 186 | "details": "Interface of the ERC165 standard, as defined in the https://eips.ethereum.org/EIPS/eip-165[EIP]. Implementers can declare support of contract interfaces, which can then be queried by others ({ERC165Checker}). For an implementation, see {ERC165}.", 187 | "kind": "dev", 188 | "methods": { 189 | "supportsInterface(bytes4)": { 190 | "details": "Returns true if this contract implements the interface defined by `interfaceId`. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas." 191 | } 192 | }, 193 | "version": 1 194 | }, 195 | "offset": [ 196 | 419, 197 | 876 198 | ], 199 | "opcodes": "", 200 | "pcMap": {}, 201 | "sha1": "4ab04b1a20a6537195293d5c943af8d8052ae944", 202 | "source": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity >0.6.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}", 203 | "sourceMap": "", 204 | "sourcePath": "contracts/interfaces/IERC165.sol", 205 | "type": "interface" 206 | } -------------------------------------------------------------------------------- /erc721/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "Legio": [ 4 | "0xD17E6E1daB2d1E778278f5358ca68D572b713cdF", 5 | "0xbc71d1049d984f261663c3b46c1F443C622852EF", 6 | "0x251568c2ba92a7CD30CF1f5a6c27dD42b167011A" 7 | ] 8 | } 9 | } -------------------------------------------------------------------------------- /erc721/contracts/interfaces/IERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) 3 | 4 | pragma solidity >0.6.0; 5 | 6 | /** 7 | * @dev Interface of the ERC165 standard, as defined in the 8 | * https://eips.ethereum.org/EIPS/eip-165[EIP]. 9 | * 10 | * Implementers can declare support of contract interfaces, which can then be 11 | * queried by others ({ERC165Checker}). 12 | * 13 | * For an implementation, see {ERC165}. 14 | */ 15 | interface IERC165 { 16 | /** 17 | * @dev Returns true if this contract implements the interface defined by 18 | * `interfaceId`. See the corresponding 19 | * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] 20 | * to learn more about how these ids are created. 21 | * 22 | * This function call must use less than 30 000 gas. 23 | */ 24 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 25 | } -------------------------------------------------------------------------------- /erc721/contracts/interfaces/IERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) 3 | 4 | pragma solidity >0.6.0; 5 | 6 | import "./IERC165.sol"; 7 | 8 | /** 9 | * @dev Required interface of an ERC721 compliant contract. 10 | */ 11 | interface IERC721 is IERC165 { 12 | /** 13 | * @dev Emitted when `tokenId` token is transferred from `from` to `to`. 14 | */ 15 | event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); 16 | 17 | /** 18 | * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. 19 | */ 20 | event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); 21 | 22 | /** 23 | * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. 24 | */ 25 | event ApprovalForAll(address indexed owner, address indexed operator, bool approved); 26 | 27 | /** 28 | * @dev Returns the number of tokens in ``owner``'s account. 29 | */ 30 | function balanceOf(address owner) external view returns (uint256 balance); 31 | 32 | /** 33 | * @dev Returns the owner of the `tokenId` token. 34 | * 35 | * Requirements: 36 | * 37 | * - `tokenId` must exist. 38 | */ 39 | function ownerOf(uint256 tokenId) external view returns (address owner); 40 | 41 | /** 42 | * @dev Safely transfers `tokenId` token from `from` to `to`. 43 | * 44 | * Requirements: 45 | * 46 | * - `from` cannot be the zero address. 47 | * - `to` cannot be the zero address. 48 | * - `tokenId` token must exist and be owned by `from`. 49 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 50 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 51 | * 52 | * Emits a {Transfer} event. 53 | */ 54 | function safeTransferFrom( 55 | address from, 56 | address to, 57 | uint256 tokenId, 58 | bytes calldata data 59 | ) external; 60 | 61 | /** 62 | * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients 63 | * are aware of the ERC721 protocol to prevent tokens from being forever locked. 64 | * 65 | * Requirements: 66 | * 67 | * - `from` cannot be the zero address. 68 | * - `to` cannot be the zero address. 69 | * - `tokenId` token must exist and be owned by `from`. 70 | * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. 71 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 72 | * 73 | * Emits a {Transfer} event. 74 | */ 75 | function safeTransferFrom( 76 | address from, 77 | address to, 78 | uint256 tokenId 79 | ) external; 80 | 81 | /** 82 | * @dev Transfers `tokenId` token from `from` to `to`. 83 | * 84 | * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. 85 | * 86 | * Requirements: 87 | * 88 | * - `from` cannot be the zero address. 89 | * - `to` cannot be the zero address. 90 | * - `tokenId` token must be owned by `from`. 91 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 92 | * 93 | * Emits a {Transfer} event. 94 | */ 95 | function transferFrom( 96 | address from, 97 | address to, 98 | uint256 tokenId 99 | ) external; 100 | 101 | /** 102 | * @dev Gives permission to `to` to transfer `tokenId` token to another account. 103 | * The approval is cleared when the token is transferred. 104 | * 105 | * Only a single account can be approved at a time, so approving the zero address clears previous approvals. 106 | * 107 | * Requirements: 108 | * 109 | * - The caller must own the token or be an approved operator. 110 | * - `tokenId` must exist. 111 | * 112 | * Emits an {Approval} event. 113 | */ 114 | function approve(address to, uint256 tokenId) external; 115 | 116 | /** 117 | * @dev Approve or remove `operator` as an operator for the caller. 118 | * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. 119 | * 120 | * Requirements: 121 | * 122 | * - The `operator` cannot be the caller. 123 | * 124 | * Emits an {ApprovalForAll} event. 125 | */ 126 | function setApprovalForAll(address operator, bool _approved) external; 127 | 128 | /** 129 | * @dev Returns the account approved for `tokenId` token. 130 | * 131 | * Requirements: 132 | * 133 | * - `tokenId` must exist. 134 | */ 135 | function getApproved(uint256 tokenId) external view returns (address operator); 136 | 137 | /** 138 | * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. 139 | * 140 | * See {setApprovalForAll} 141 | */ 142 | function isApprovedForAll(address owner, address operator) external view returns (bool); 143 | } -------------------------------------------------------------------------------- /erc721/contracts/interfaces/IERC721Metadata.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./IERC721.sol"; 7 | 8 | /** 9 | * @title ERC-721 Non-Fungible Token Standard, optional metadata extension 10 | * @dev See https://eips.ethereum.org/EIPS/eip-721 11 | */ 12 | interface IERC721Metadata is IERC721 { 13 | /** 14 | * @dev Returns the token collection name. 15 | */ 16 | function name() external view returns (string memory); 17 | 18 | /** 19 | * @dev Returns the token collection symbol. 20 | */ 21 | function symbol() external view returns (string memory); 22 | 23 | /** 24 | * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. 25 | */ 26 | function tokenURI(uint256 tokenId) external view returns (string memory); 27 | } -------------------------------------------------------------------------------- /erc721/contracts/interfaces/IERC721Receiver.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol) 3 | 4 | pragma solidity >0.6.0; 5 | 6 | /** 7 | * @title ERC721 token receiver interface 8 | * @dev Interface for any contract that wants to support safeTransfers 9 | * from ERC721 asset contracts. 10 | */ 11 | interface IERC721Receiver { 12 | /** 13 | * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} 14 | * by `operator` from `from`, this function is called. 15 | * 16 | * It must return its Solidity selector to confirm the token transfer. 17 | * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. 18 | * 19 | * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`. 20 | */ 21 | function onERC721Received( 22 | address operator, 23 | address from, 24 | uint256 tokenId, 25 | bytes calldata data 26 | ) external returns (bytes4); 27 | } -------------------------------------------------------------------------------- /erc721/contracts/utils/String.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >0.6.0; 4 | 5 | /** 6 | * @dev String operations. 7 | */ 8 | library Strings { 9 | bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; 10 | 11 | /** 12 | * @dev Converts a `uint256` to its ASCII `string` decimal representation. 13 | */ 14 | function toString(uint256 value) internal pure returns (string memory) { 15 | // Inspired by OraclizeAPI's implementation - MIT licence 16 | // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol 17 | 18 | if (value == 0) { 19 | return "0"; 20 | } 21 | uint256 temp = value; 22 | uint256 digits; 23 | while (temp != 0) { 24 | digits++; 25 | temp /= 10; 26 | } 27 | bytes memory buffer = new bytes(digits); 28 | while (value != 0) { 29 | digits -= 1; 30 | buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); 31 | value /= 10; 32 | } 33 | return string(buffer); 34 | } 35 | 36 | /** 37 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. 38 | */ 39 | function toHexString(uint256 value) internal pure returns (string memory) { 40 | if (value == 0) { 41 | return "0x00"; 42 | } 43 | uint256 temp = value; 44 | uint256 length = 0; 45 | while (temp != 0) { 46 | length++; 47 | temp >>= 8; 48 | } 49 | return toHexString(value, length); 50 | } 51 | 52 | /** 53 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. 54 | */ 55 | function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { 56 | bytes memory buffer = new bytes(2 * length + 2); 57 | buffer[0] = "0"; 58 | buffer[1] = "x"; 59 | for (uint256 i = 2 * length + 1; i > 1; --i) { 60 | buffer[i] = _HEX_SYMBOLS[value & 0xf]; 61 | value >>= 4; 62 | } 63 | require(value == 0, "Strings: hex length insufficient"); 64 | return string(buffer); 65 | } 66 | } -------------------------------------------------------------------------------- /erc721/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/erc721/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /erc721/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import Legio, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract Legio...") 8 | deploy_wallet = Legio.deploy({"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "a+") as dep: 12 | dep.write("Legio => https://rinkeby.etherscan.io/address/"+deploy_wallet.address+"\n\n") 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /ether_wallet/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /ether_wallet/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "EtherWallet": [ 4 | "0x72a8422a0E0098eF770A0dfdA312Ec1bd44fdB44" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /ether_wallet/contracts/EtherWallet.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | /* 5 | * @title: EtherWallet, a crowdfunding smart contract. 6 | * @author: Anthony (fps) https://github.com/0xfps. 7 | * @dev: Ether Wallet: https://github.com/0xfps/my-solidity/tree/main/ether_wallet 8 | * This is a simple Solidity program that allows anyone to send ether to a wallet then allowing only the owner to withdraw. 9 | */ 10 | contract EtherWallet { 11 | // Declare owner, deploy time, ended, and locking. 12 | address owner; 13 | uint256 deploy_time; 14 | bool ended; 15 | bool locked; 16 | 17 | // Events. 18 | event Deployed(address, uint256); // owner, deploy_time. 19 | event Funded(address, uint256); // msg.sender, msg.value. 20 | event Withdraw(address, uint256); // owner, address(this).balance. 21 | 22 | constructor() { 23 | owner = msg.sender; // Set the owner of the contract to the deployer. 24 | deploy_time = block.timestamp; // Set time of deployment. 25 | ended = false; // Ended to control the funding. 26 | emit Deployed(owner, deploy_time); 27 | } 28 | 29 | modifier NoReentrance() { 30 | require(!locked, "You cannot redo this action."); 31 | locked = true; 32 | _; 33 | locked = false; 34 | } 35 | 36 | function fund() public payable NoReentrance { 37 | require(msg.sender != address(0), "!Address"); 38 | require(msg.sender != owner, "Owner !Send"); 39 | emit Funded(msg.sender, msg.value); 40 | } 41 | 42 | function viewFunds() public view returns(uint256 balance) { 43 | require(msg.sender == owner, "!Owner"); 44 | balance = address(this).balance; 45 | } 46 | 47 | function withdrawFunds() public payable NoReentrance { 48 | require(msg.sender == owner, "!Owner"); 49 | uint256 bal = address(this).balance; 50 | payable(owner).transfer(address(this).balance); 51 | emit Withdraw(msg.sender, bal); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ether_wallet/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/ether_wallet/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /ether_wallet/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import EtherWallet, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract EtherWallet...") 8 | deploy_wallet = EtherWallet.deploy({"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "a+") as dep: 12 | dep.write("\n\nEther Wallet => https://rinkeby.etherscan.io/address/"+deploy_wallet.address) 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /iterable_mapping/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /iterable_mapping/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "IterableMapping": [ 4 | "0x1A09e937AB84b5434a70aDaBC69b9884B85ED123" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /iterable_mapping/contracts/IterableMapping.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | /** 5 | * @title Iterable Mapping. 6 | * @author Anthony (fps) https://github.com/0xfps. 7 | * @dev 8 | */ 9 | contract IterableMapping { 10 | // array containing 10 elements 11 | bytes32[10] transaction_hashes; 12 | uint8 control; 13 | bool locked; 14 | // map the hashes to the receiver 15 | mapping(bytes32 => address) map; 16 | 17 | receive() payable external {} 18 | fallback() payable external {} 19 | 20 | modifier NoReentrance() { 21 | require(!locked, "You cannot redo this action."); 22 | locked = true; 23 | _; 24 | locked = false; 25 | } 26 | 27 | // write a transaction function 28 | function Transact(address to, uint amount) public NoReentrance { 29 | require(control < 10, "Transaction records are full."); 30 | payable(to).call{value: amount}(""); 31 | bytes32 tx_hash = keccak256(abi.encodePacked(msg.sender, to, amount)); 32 | transaction_hashes[control] = tx_hash; 33 | control = control + 1; 34 | map[tx_hash] = to; 35 | } 36 | 37 | function Get_Hash_Receiver(uint8 index) public view returns(address) { 38 | require(index < control, "Index not recorded"); 39 | address receiver = map[transaction_hashes[index]]; 40 | // return string(abi.encodePacked("Address of receceiver with hash ", transaction_hashes[index], " is ", receiver)); 41 | return receiver; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /iterable_mapping/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/iterable_mapping/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /iterable_mapping/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import IterableMapping, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract EtherWallet...") 8 | deploy_wallet = IterableMapping.deploy({"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "r+") as dep: 12 | dep.write("\n\nIterable Mapping => https://rinkeby.etherscan.io/address/"+deploy_wallet.address) 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /liquidity/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later 2 | 3 | pragma solidity >0.6.0; 4 | 5 | interface IERC20 { 6 | event Approval(address indexed owner, address indexed spender, uint value); 7 | event Transfer(address indexed from, address indexed to, uint value); 8 | 9 | function name() external view returns (string memory); 10 | function symbol() external view returns (string memory); 11 | function decimals() external view returns (uint8); 12 | function totalSupply() external view returns (uint); 13 | function balanceOf(address owner) external view returns (uint); 14 | function allowance(address owner, address spender) external view returns (uint); 15 | 16 | function approve(address spender, uint value) external returns (bool); 17 | function transfer(address to, uint value) external returns (bool); 18 | function transferFrom(address from, address to, uint value) external returns (bool); 19 | } 20 | -------------------------------------------------------------------------------- /liquidity/IUniswapV2Factory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later 2 | 3 | pragma solidity >0.6.0; 4 | 5 | interface IUniswapV2Factory { 6 | event PairCreated(address indexed token0, address indexed token1, address pair, uint); 7 | 8 | function feeTo() external view returns (address); 9 | function feeToSetter() external view returns (address); 10 | 11 | function getPair(address tokenA, address tokenB) external view returns (address pair); 12 | function allPairs(uint) external view returns (address pair); 13 | function allPairsLength() external view returns (uint); 14 | 15 | function createPair(address tokenA, address tokenB) external returns (address pair); 16 | 17 | function setFeeTo(address) external; 18 | function setFeeToSetter(address) external; 19 | } 20 | -------------------------------------------------------------------------------- /liquidity/IUniswapV2Pair.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later 2 | 3 | pragma solidity >0.6.0; 4 | 5 | interface IUniswapV2Pair { 6 | event Approval(address indexed owner, address indexed spender, uint value); 7 | event Transfer(address indexed from, address indexed to, uint value); 8 | 9 | function name() external pure returns (string memory); 10 | function symbol() external pure returns (string memory); 11 | function decimals() external pure returns (uint8); 12 | function totalSupply() external view returns (uint); 13 | function balanceOf(address owner) external view returns (uint); 14 | function allowance(address owner, address spender) external view returns (uint); 15 | 16 | function approve(address spender, uint value) external returns (bool); 17 | function transfer(address to, uint value) external returns (bool); 18 | function transferFrom(address from, address to, uint value) external returns (bool); 19 | 20 | function DOMAIN_SEPARATOR() external view returns (bytes32); 21 | function PERMIT_TYPEHASH() external pure returns (bytes32); 22 | function nonces(address owner) external view returns (uint); 23 | 24 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; 25 | 26 | event Mint(address indexed sender, uint amount0, uint amount1); 27 | event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); 28 | event Swap( 29 | address indexed sender, 30 | uint amount0In, 31 | uint amount1In, 32 | uint amount0Out, 33 | uint amount1Out, 34 | address indexed to 35 | ); 36 | event Sync(uint112 reserve0, uint112 reserve1); 37 | 38 | function MINIMUM_LIQUIDITY() external pure returns (uint); 39 | function factory() external view returns (address); 40 | function token0() external view returns (address); 41 | function token1() external view returns (address); 42 | function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); 43 | function price0CumulativeLast() external view returns (uint); 44 | function price1CumulativeLast() external view returns (uint); 45 | function kLast() external view returns (uint); 46 | 47 | function mint(address to) external returns (uint liquidity); 48 | function burn(address to) external returns (uint amount0, uint amount1); 49 | function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; 50 | function skim(address to) external; 51 | function sync() external; 52 | 53 | function initialize(address, address) external; 54 | } 55 | -------------------------------------------------------------------------------- /liquidity/IUniswapV2Router01.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later 2 | 3 | pragma solidity >0.6.0; 4 | 5 | interface IUniswapV2Router01 { 6 | function factory() external pure returns (address); 7 | function WETH() external pure returns (address); 8 | 9 | function addLiquidity( 10 | address tokenA, 11 | address tokenB, 12 | uint amountADesired, 13 | uint amountBDesired, 14 | uint amountAMin, 15 | uint amountBMin, 16 | address to, 17 | uint deadline 18 | ) external returns (uint amountA, uint amountB, uint liquidity); 19 | function addLiquidityETH( 20 | address token, 21 | uint amountTokenDesired, 22 | uint amountTokenMin, 23 | uint amountETHMin, 24 | address to, 25 | uint deadline 26 | ) external payable returns (uint amountToken, uint amountETH, uint liquidity); 27 | function removeLiquidity( 28 | address tokenA, 29 | address tokenB, 30 | uint liquidity, 31 | uint amountAMin, 32 | uint amountBMin, 33 | address to, 34 | uint deadline 35 | ) external returns (uint amountA, uint amountB); 36 | function removeLiquidityETH( 37 | address token, 38 | uint liquidity, 39 | uint amountTokenMin, 40 | uint amountETHMin, 41 | address to, 42 | uint deadline 43 | ) external returns (uint amountToken, uint amountETH); 44 | function removeLiquidityWithPermit( 45 | address tokenA, 46 | address tokenB, 47 | uint liquidity, 48 | uint amountAMin, 49 | uint amountBMin, 50 | address to, 51 | uint deadline, 52 | bool approveMax, uint8 v, bytes32 r, bytes32 s 53 | ) external returns (uint amountA, uint amountB); 54 | function removeLiquidityETHWithPermit( 55 | address token, 56 | uint liquidity, 57 | uint amountTokenMin, 58 | uint amountETHMin, 59 | address to, 60 | uint deadline, 61 | bool approveMax, uint8 v, bytes32 r, bytes32 s 62 | ) external returns (uint amountToken, uint amountETH); 63 | function swapExactTokensForTokens( 64 | uint amountIn, 65 | uint amountOutMin, 66 | address[] calldata path, 67 | address to, 68 | uint deadline 69 | ) external returns (uint[] memory amounts); 70 | function swapTokensForExactTokens( 71 | uint amountOut, 72 | uint amountInMax, 73 | address[] calldata path, 74 | address to, 75 | uint deadline 76 | ) external returns (uint[] memory amounts); 77 | function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) 78 | external 79 | payable 80 | returns (uint[] memory amounts); 81 | function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) 82 | external 83 | returns (uint[] memory amounts); 84 | function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) 85 | external 86 | returns (uint[] memory amounts); 87 | function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) 88 | external 89 | payable 90 | returns (uint[] memory amounts); 91 | 92 | function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); 93 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); 94 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); 95 | function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); 96 | function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); 97 | } 98 | -------------------------------------------------------------------------------- /liquidity/IUniswapV2Router02.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later 2 | 3 | pragma solidity >0.6.0; 4 | 5 | import './IUniswapV2Router01.sol'; 6 | 7 | interface IUniswapV2Router02 is IUniswapV2Router01 { 8 | function removeLiquidityETHSupportingFeeOnTransferTokens( 9 | address token, 10 | uint liquidity, 11 | uint amountTokenMin, 12 | uint amountETHMin, 13 | address to, 14 | uint deadline 15 | ) external returns (uint amountETH); 16 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( 17 | address token, 18 | uint liquidity, 19 | uint amountTokenMin, 20 | uint amountETHMin, 21 | address to, 22 | uint deadline, 23 | bool approveMax, uint8 v, bytes32 r, bytes32 s 24 | ) external returns (uint amountETH); 25 | 26 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( 27 | uint amountIn, 28 | uint amountOutMin, 29 | address[] calldata path, 30 | address to, 31 | uint deadline 32 | ) external; 33 | function swapExactETHForTokensSupportingFeeOnTransferTokens( 34 | uint amountOutMin, 35 | address[] calldata path, 36 | address to, 37 | uint deadline 38 | ) external payable; 39 | function swapExactTokensForETHSupportingFeeOnTransferTokens( 40 | uint amountIn, 41 | uint amountOutMin, 42 | address[] calldata path, 43 | address to, 44 | uint deadline 45 | ) external; 46 | } 47 | -------------------------------------------------------------------------------- /liquidity/IWETH.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later 2 | 3 | pragma solidity >0.6.0; 4 | 5 | interface IWETH { 6 | function deposit() external payable; 7 | function transfer(address to, uint value) external returns (bool); 8 | function withdraw(uint) external; 9 | } 10 | -------------------------------------------------------------------------------- /liquidity/SafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later 2 | 3 | pragma solidity >0.6.0; 4 | 5 | // a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math) 6 | 7 | library SafeMath { 8 | function add(uint x, uint y) internal pure returns (uint z) { 9 | require((z = x + y) >= x, 'ds-math-add-overflow'); 10 | } 11 | 12 | function sub(uint x, uint y) internal pure returns (uint z) { 13 | require((z = x - y) <= x, 'ds-math-sub-underflow'); 14 | } 15 | 16 | function mul(uint x, uint y) internal pure returns (uint z) { 17 | require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /liquidity/TransferHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later 2 | 3 | pragma solidity >0.6.0; 4 | 5 | // helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false 6 | library TransferHelper { 7 | function safeApprove( 8 | address token, 9 | address to, 10 | uint256 value 11 | ) internal { 12 | // bytes4(keccak256(bytes('approve(address,uint256)'))); 13 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value)); 14 | require( 15 | success && (data.length == 0 || abi.decode(data, (bool))), 16 | 'TransferHelper::safeApprove: approve failed' 17 | ); 18 | } 19 | 20 | function safeTransfer( 21 | address token, 22 | address to, 23 | uint256 value 24 | ) internal { 25 | // bytes4(keccak256(bytes('transfer(address,uint256)'))); 26 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value)); 27 | require( 28 | success && (data.length == 0 || abi.decode(data, (bool))), 29 | 'TransferHelper::safeTransfer: transfer failed' 30 | ); 31 | } 32 | 33 | function safeTransferFrom( 34 | address token, 35 | address from, 36 | address to, 37 | uint256 value 38 | ) internal { 39 | // bytes4(keccak256(bytes('transferFrom(address,address,uint256)'))); 40 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value)); 41 | require( 42 | success && (data.length == 0 || abi.decode(data, (bool))), 43 | 'TransferHelper::transferFrom: transferFrom failed' 44 | ); 45 | } 46 | 47 | function safeTransferETH(address to, uint256 value) internal { 48 | (bool success, ) = to.call{value: value}(new bytes(0)); 49 | require(success, 'TransferHelper::safeTransferETH: ETH transfer failed'); 50 | } 51 | } -------------------------------------------------------------------------------- /liquidity/UniswapV2Library.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-or-later 2 | 3 | pragma solidity >0.6.0; 4 | 5 | import './IUniswapV2Pair.sol'; 6 | 7 | import "./SafeMath.sol"; 8 | 9 | library UniswapV2Library { 10 | using SafeMath for uint; 11 | 12 | // returns sorted token addresses, used to handle return values from pairs sorted in this order 13 | function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { 14 | require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES'); 15 | (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); 16 | require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS'); 17 | } 18 | 19 | // calculates the CREATE2 address for a pair without making any external calls 20 | function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) { 21 | (address token0, address token1) = sortTokens(tokenA, tokenB); 22 | pair = address(uint(keccak256(abi.encodePacked( 23 | hex'ff', 24 | factory, 25 | keccak256(abi.encodePacked(token0, token1)), 26 | hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash 27 | )))); 28 | } 29 | 30 | // fetches and sorts the reserves for a pair 31 | function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { 32 | (address token0,) = sortTokens(tokenA, tokenB); 33 | (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves(); 34 | (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); 35 | } 36 | 37 | // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset 38 | function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { 39 | require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT'); 40 | require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY'); 41 | amountB = amountA.mul(reserveB) / reserveA; 42 | } 43 | 44 | // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset 45 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { 46 | require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT'); 47 | require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY'); 48 | uint amountInWithFee = amountIn.mul(997); 49 | uint numerator = amountInWithFee.mul(reserveOut); 50 | uint denominator = reserveIn.mul(1000).add(amountInWithFee); 51 | amountOut = numerator / denominator; 52 | } 53 | 54 | // given an output amount of an asset and pair reserves, returns a required input amount of the other asset 55 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { 56 | require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT'); 57 | require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY'); 58 | uint numerator = reserveIn.mul(amountOut).mul(1000); 59 | uint denominator = reserveOut.sub(amountOut).mul(997); 60 | amountIn = (numerator / denominator).add(1); 61 | } 62 | 63 | // performs chained getAmountOut calculations on any number of pairs 64 | function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { 65 | require(path.length >= 2, 'UniswapV2Library: INVALID_PATH'); 66 | amounts = new uint[](path.length); 67 | amounts[0] = amountIn; 68 | for (uint i; i < path.length - 1; i++) { 69 | (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]); 70 | amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); 71 | } 72 | } 73 | 74 | // performs chained getAmountIn calculations on any number of pairs 75 | function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { 76 | require(path.length >= 2, 'UniswapV2Library: INVALID_PATH'); 77 | amounts = new uint[](path.length); 78 | amounts[amounts.length - 1] = amountOut; 79 | for (uint i = path.length - 1; i > 0; i--) { 80 | (uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]); 81 | amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /merkle_tree/Description.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** 4 | M E R K L E T R E E 5 | 6 | --- What is a Merkle Tree? --- 7 | 8 | - A Merkle tree is a hash-based data structure that is a generalization of the hash list. 9 | - It is a tree structure in which each leaf node is a hash of a block of data. 10 | - Each non-leaf node is a hash of its children. 11 | - Typically, Merkle trees have a branching factor of 2, meaning that each node has up to 2 children. 12 | 13 | - Merkle trees are used in distributed systems for efficient data verification. 14 | - They are efficient because they use hashes instead of full files. 15 | - Hashes are ways of encoding files that are much smaller than the actual file itself. 16 | - Currently, their main uses are in peer-to-peer networks such as Tor, Bitcoin, and Git. 17 | 18 | 19 | 20 | --- How to build a MerkleTree? --- 21 | 22 | - We need to first have a list of transactions that we will. It is advisable that the transactions used for a Merkle Tree 23 | should be in powers of 2, or should be even, i.e, the number of the transactions should be in 2^n. But should the number be odd, we need to 24 | duplicate the last transaction to make it even. 25 | 26 | - Then we pair up the transactions in 2s and hash them, and the resulting hashes, we pair them again and hash them again. 27 | 28 | - In the end: 👇🏾👇🏾👇🏾 29 | 30 | 31 | ________________ 32 | | | 33 | | Tx 1,2, 3, 4 | 34 | |______________| 35 | | 36 | | 37 | | 38 | | 39 | _____________________________________________________________________ 40 | | | 41 | | | 42 | | | 43 | | | 44 | ______________ ______________ 45 | | | | | 46 | | Tx 1,2 | | Tx 3,4 | 47 | |____________| |____________| 48 | | | 49 | | | 50 | | | 51 | | | 52 | ______________________________________ ______________________________________ 53 | | | | | 54 | | | | | 55 | | | | | 56 | | | | | 57 | ______________ ______________ ______________ ______________ 58 | | | | | | | | | 59 | | Tx 1 | | Tx 2 | | Tx 3 | | Tx 4 | 60 | |____________| |____________| |____________| |____________| 61 | */ -------------------------------------------------------------------------------- /merkle_tree/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /merkle_tree/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "MerkleTree": [ 4 | "0x7fF08E0dd90bBf3B22008fB1b28Bb4B037a8B79D" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /merkle_tree/contracts/MerkleTree.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | /** 5 | * @title Merkle Tree. 6 | * @author Anthony (fps) https://github.com/0xfps. 7 | * @dev I believe youve gone through the description.md file to know what a Merkle Tree is all about. Its pretty big innit? 8 | */ 9 | contract MerkleTree { 10 | /** 11 | * I will be needing some public functions, and i will avoid verification like i did on multi sig wallet 12 | 13 | * Function 1 (Make_Transaction): 14 | * - Make a transaction. 15 | * - Hash the transaction. 16 | * - Adds the hashed transaction to a list. 17 | 18 | * Function 2 (Start_Merkle): 19 | * - Performs the act explained in description.md 20 | */ 21 | 22 | address payable owner; 23 | // for reentrancy 24 | bool locked; 25 | // This array will be useful when we want to compute out merkle tree 26 | bytes32[][] merkle; 27 | // This array will be a storage for all our transactions 28 | bytes32[] all_transactions; 29 | 30 | modifier No_Reentrancy() { 31 | require(!locked, "You cant repeat this action"); 32 | locked = true; 33 | _; 34 | locked = false; 35 | } 36 | 37 | constructor() { 38 | // first I will need to assign the owner to myself. 😌 39 | owner = payable(msg.sender); 40 | } 41 | 42 | // I will have a function that allows us to make a transaction and will add the transaction to an array; 43 | function Make_Transaction(address receiver, uint amount) payable public No_Reentrancy { 44 | // payable(receiver).transfer(amount); 45 | payable(receiver).call{value: amount}(""); 46 | // This string(abi.encodePacked(a, b, c)) will stringify all the actions done and add them to an array "all_transactions" 47 | all_transactions.push(keccak256(abi.encodePacked(msg.sender, receiver, amount))); 48 | } 49 | 50 | function Compute_Merkle() internal { 51 | // The most important thing, getting the length of the last array in the merkle 52 | bytes32[] memory this_merkle = merkle[merkle.length - 1]; 53 | uint len_last_merkle_list = this_merkle.length; 54 | 55 | // if the length is one then it should stop 56 | if(len_last_merkle_list == 1) { 57 | // do nothing 58 | } else { 59 | // if the length is greater than one, then some calculations would be needed. 60 | // We need to group them in twos and duplicate the last on if its odd 61 | // Then update the merkle list 62 | uint even_or_odd = len_last_merkle_list % 2; 63 | 64 | if(even_or_odd == 1) { 65 | uint new_length = (len_last_merkle_list / 2) + 1; 66 | bytes32[] memory append = new bytes32[](new_length); 67 | // if its odd 68 | // Here we will consider the last list in the merkle because we are going to duplicate it. 69 | // if the index is not the last index of this_merkle 70 | 71 | for (uint x = 0; x < len_last_merkle_list; x+=2) { 72 | 73 | // if x is not the last inde 74 | if(x == (len_last_merkle_list - 1)) { 75 | // this is the last one so should be hashed twice. 76 | append[x] = keccak256(abi.encodePacked(this_merkle[x], this_merkle[x])); 77 | } else { 78 | // it should group them in twos and hash. 79 | append[x] = keccak256(abi.encodePacked(this_merkle[x], this_merkle[x+1])); 80 | } 81 | } 82 | 83 | merkle.push(append); 84 | } else { 85 | // if the merkle length is even 86 | // develop the length of the new array from the length of the initial one i.e initial / 2; 87 | uint new_length = len_last_merkle_list / 2; 88 | // create a new array 89 | bytes32[] memory append = new bytes32[](new_length); 90 | 91 | // loop and group them into twos and hash 92 | for (uint x = 0; x < len_last_merkle_list; x+=2) { 93 | // it should group them in twos and hash. 94 | append[x] = keccak256(abi.encodePacked(this_merkle[x], this_merkle[x+1])); 95 | } 96 | 97 | merkle.push(append); 98 | } 99 | 100 | Compute_Merkle(); 101 | } 102 | } 103 | 104 | function See_Merkle_Root_Hash() public view returns(bytes32) { 105 | return merkle[merkle.length - 1][0]; 106 | } 107 | 108 | function Start_Merkle() public { 109 | if(merkle.length > 0) { 110 | delete merkle; 111 | } 112 | 113 | // merkle computation starts here 114 | // first, we need to get the length of the transaction array and do a loop that calls a function. 115 | uint tx_length = all_transactions.length; 116 | 117 | require(tx_length > 1, "Cannot compute merkle length for this transaction records."); 118 | require(tx_length < 3, "Transaction record too long for a merkle computation."); 119 | 120 | // first we loop through the all_transactions array to add them to the merkle as the base ot leafs. 121 | // this will generate the first array in out merkle array. 122 | // declare a new memory uint 123 | bytes32[] memory mem = new bytes32[](tx_length); 124 | 125 | for (uint i = 0; i < tx_length; i++) { 126 | mem[i] = all_transactions[i]; 127 | } 128 | 129 | merkle.push(mem); 130 | // Compute_Merkle(); 131 | } 132 | 133 | function Get_TX_Length() public view returns(uint) { 134 | return all_transactions.length; 135 | } 136 | 137 | function Get_Merke_Length() public view returns(uint) { 138 | return merkle.length; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /merkle_tree/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/merkle_tree/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /merkle_tree/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import MerkleTree, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract EtherWallet...") 8 | deploy_wallet = MerkleTree.deploy({"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "r+") as dep: 12 | dep.write("\n\nMerkle Tree => "+deploy_wallet.address) 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() -------------------------------------------------------------------------------- /multi_sig_wallet/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /multi_sig_wallet/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | { 2 | "4": { 3 | "MultiSigWallet": [ 4 | "0x14C6Bb868EB71cAaDf19601699C760926511578F" 5 | ] 6 | } 7 | } -------------------------------------------------------------------------------- /multi_sig_wallet/contracts/MultiSigWallet.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | /** 5 | * @title MultiSig Wallet. 6 | * @author Anthony (fps) https://github.com/0xfps. 7 | * @dev 8 | * D E S C R I P T I O N 9 | * A basic solidity program that allows the creation of a wallet in the contract. 10 | * Wallet owners can: 11 | * 1. Submit a transaction. 12 | * 2. Approve and revoke a pending transaction. 13 | * 3. Anyone can execute a transaction after enough owners has approved it. 14 | */ 15 | contract MultiSigWallet { 16 | struct Data { 17 | address wallet_owner; 18 | uint256 funds; 19 | uint256 deposit_to_receiver; 20 | address receiver; 21 | int256 approve_count; 22 | } 23 | 24 | mapping(address => Data) private owners; 25 | uint256 public wallets; 26 | 27 | function createWallet(address _creator) public payable { 28 | require(msg.sender != address(0), "!Address"); 29 | require(_creator != address(0), "!Creator Address"); 30 | require(owners[_creator].wallet_owner == address(0), "Wallet created already."); 31 | require(msg.value > 0, "Creation fund == 0"); 32 | owners[_creator] = Data(_creator, msg.value, 0, address(0), 0); 33 | wallets ++; 34 | } 35 | 36 | function getFunds(address acc) private view returns(uint funds) { 37 | funds = owners[acc].funds; 38 | } 39 | 40 | function fundWallet() public payable { 41 | require(msg.sender != address(0), "!Address"); // Valid address. 42 | require(owners[msg.sender].wallet_owner == msg.sender, "Wallet !Created"); 43 | owners[msg.sender].funds += msg.value; 44 | // Funds the contract on his behalf but has a record of how much he has deposited. 45 | } 46 | 47 | function makeTransaction(address _receiver, uint _amount) public { 48 | require(msg.sender != address(0), "!Address"); // Valid address. 49 | require(_receiver != address(0), "!Receiver Address"); // Valid receiver. 50 | require(_receiver != msg.sender, "Sender ! Receiver"); 51 | require(owners[msg.sender].wallet_owner != address(0), "Wallet !Created"); 52 | require(owners[msg.sender].receiver == address(0), "There is a pending txn"); // There is no pending transaction. 53 | require(owners[_receiver].wallet_owner != address(0), "Receiver !created."); 54 | require(getFunds(msg.sender) > _amount, "Funds < value"); 55 | owners[msg.sender].receiver = _receiver; 56 | owners[msg.sender].funds -= _amount; 57 | owners[msg.sender].deposit_to_receiver += _amount; 58 | } 59 | 60 | function confirmTransaction(address _txn_maker) public { 61 | require(msg.sender != address(0), "!Address"); // Valid address. 62 | require(owners[msg.sender].wallet_owner != address(0), "Wallet !Created"); 63 | require(msg.sender != owners[_txn_maker].wallet_owner, "!Approve"); 64 | require(owners[_txn_maker].wallet_owner != address(0), "Wallet !Created"); 65 | require(owners[_txn_maker].receiver != address(0), "!Receiver in this txn"); 66 | owners[_txn_maker].approve_count += 1; 67 | } 68 | 69 | function revokeTransaction(address _txn_maker) public { 70 | require(msg.sender != address(0), "!Address"); // Valid address. 71 | require(owners[msg.sender].wallet_owner != address(0), "Wallet !Created"); 72 | require(owners[_txn_maker].wallet_owner != address(0), "Wallet !Created"); 73 | require(msg.sender != owners[_txn_maker].wallet_owner, "!Revoke"); 74 | require(owners[_txn_maker].receiver != address(0), "!Receiver in this txn"); 75 | owners[_txn_maker].approve_count -= 1; 76 | } 77 | 78 | function finishTransaction(address _txn_maker) public payable { 79 | require(msg.sender != address(0), "!Address"); // Valid address. 80 | require(owners[_txn_maker].wallet_owner != address(0), "Wallet !Created"); 81 | require(msg.sender == owners[_txn_maker].wallet_owner, "!Finish"); 82 | require(owners[_txn_maker].receiver != address(0), "!Receiver in this txn"); 83 | require(owners[_txn_maker].approve_count > int256(wallets / 2), "Not approved yet."); 84 | uint256 temp_bal = owners[_txn_maker].deposit_to_receiver; 85 | address _receiver_wallet = owners[_txn_maker].receiver; 86 | payable(_receiver_wallet).transfer(temp_bal); 87 | owners[_txn_maker].deposit_to_receiver = 0; 88 | delete owners[_txn_maker].receiver; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /multi_sig_wallet/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/multi_sig_wallet/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /multi_sig_wallet/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import MultiSigWallet, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract EtherWallet...") 8 | deploy_wallet = MultiSigWallet.deploy({"from": account}, publish_source = True) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "a+") as dep: 12 | dep.write("\n\nMulti Sig Wallet => https://rinkeby.etherscan.io/address/"+deploy_wallet.address) 13 | 14 | def get_account(): 15 | if network.show_active() == "development": 16 | return accounts[0] 17 | else: 18 | return accounts.add(config['wallet']['from_key']) 19 | 20 | 21 | def main(): 22 | deploy() -------------------------------------------------------------------------------- /token_task/brownie-config.yaml: -------------------------------------------------------------------------------- 1 | dotenv: .env 2 | wallet: 3 | from_key: ${PRIVATE_KEY} -------------------------------------------------------------------------------- /token_task/build/deployments/map.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /token_task/contracts/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Interface of the ERC20 standard as defined in the EIP. 8 | */ 9 | interface IERC20 { 10 | /** 11 | * @dev Returns the amount of tokens in existence. 12 | */ 13 | function totalSupply() external view returns (uint256); 14 | 15 | /** 16 | * @dev Returns the amount of tokens owned by `account`. 17 | */ 18 | function balanceOf(address account) external view returns (uint256); 19 | 20 | /** 21 | * @dev Moves `amount` tokens from the caller's account to `to`. 22 | * 23 | * Returns a boolean value indicating whether the operation succeeded. 24 | * 25 | * Emits a {Transfer} event. 26 | */ 27 | function transfer(address to, uint256 amount) external returns (bool); 28 | 29 | /** 30 | * @dev Returns the remaining number of tokens that `spender` will be 31 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 32 | * zero by default. 33 | * 34 | * This value changes when {approve} or {transferFrom} are called. 35 | */ 36 | function allowance(address owner, address spender) external view returns (uint256); 37 | 38 | /** 39 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 40 | * 41 | * Returns a boolean value indicating whether the operation succeeded. 42 | * 43 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 44 | * that someone may use both the old and the new allowance by unfortunate 45 | * transaction ordering. One possible solution to mitigate this race 46 | * condition is to first reduce the spender's allowance to 0 and set the 47 | * desired value afterwards: 48 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 49 | * 50 | * Emits an {Approval} event. 51 | */ 52 | function approve(address spender, uint256 amount) external returns (bool); 53 | 54 | /** 55 | * @dev Moves `amount` tokens from `from` to `to` using the 56 | * allowance mechanism. `amount` is then deducted from the caller's 57 | * allowance. 58 | * 59 | * Returns a boolean value indicating whether the operation succeeded. 60 | * 61 | * Emits a {Transfer} event. 62 | */ 63 | function transferFrom( 64 | address from, 65 | address to, 66 | uint256 amount 67 | ) external returns (bool); 68 | 69 | /** 70 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 71 | * another (`to`). 72 | * 73 | * Note that `value` may be zero. 74 | */ 75 | event Transfer(address indexed from, address indexed to, uint256 value); 76 | 77 | /** 78 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 79 | * a call to {approve}. `value` is the new allowance. 80 | */ 81 | event Approval(address indexed owner, address indexed spender, uint256 value); 82 | } -------------------------------------------------------------------------------- /token_task/contracts/Liquidity.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | //////////////////////////////// 5 | ///////// Interfaces /////////// 6 | //////////////////////////////// 7 | 8 | interface IUniswapV2Factory { 9 | 10 | event PairCreated(address indexed token0, address indexed token1, address pair, uint); 11 | 12 | function feeTo() external view returns (address); 13 | 14 | function feeToSetter() external view returns (address); 15 | 16 | function getPair(address tokenA, address tokenB) external view returns (address pair); 17 | 18 | function allPairs(uint) external view returns (address pair); 19 | 20 | function allPairsLength() external view returns (uint); 21 | 22 | function createPair(address tokenA, address tokenB) external returns (address pair); 23 | 24 | function setFeeTo(address) external; 25 | 26 | function setFeeToSetter(address) external; 27 | 28 | } 29 | 30 | 31 | 32 | 33 | interface IUniswapV2Pair { 34 | 35 | event Approval(address indexed owner, address indexed spender, uint value); 36 | 37 | event Transfer(address indexed from, address indexed to, uint value); 38 | 39 | function name() external pure returns (string memory); 40 | 41 | function symbol() external pure returns (string memory); 42 | 43 | function decimals() external pure returns (uint8); 44 | 45 | function totalSupply() external view returns (uint); 46 | 47 | function balanceOf(address owner) external view returns (uint); 48 | 49 | function allowance(address owner, address spender) external view returns (uint); 50 | 51 | function approve(address spender, uint value) external returns (bool); 52 | 53 | function transfer(address to, uint value) external returns (bool); 54 | 55 | function transferFrom(address from, address to, uint value) external returns (bool); 56 | 57 | function DOMAIN_SEPARATOR() external view returns (bytes32); 58 | 59 | function PERMIT_TYPEHASH() external pure returns (bytes32); 60 | 61 | function nonces(address owner) external view returns (uint); 62 | 63 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; 64 | 65 | event Mint(address indexed sender, uint amount0, uint amount1); 66 | 67 | event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); 68 | 69 | event Swap( 70 | address indexed sender, 71 | uint amount0In, 72 | uint amount1In, 73 | uint amount0Out, 74 | uint amount1Out, 75 | address indexed to 76 | ); 77 | 78 | event Sync(uint112 reserve0, uint112 reserve1); 79 | 80 | function MINIMUM_LIQUIDITY() external pure returns (uint); 81 | 82 | function factory() external view returns (address); 83 | 84 | function token0() external view returns (address); 85 | 86 | function token1() external view returns (address); 87 | 88 | function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); 89 | 90 | function price0CumulativeLast() external view returns (uint); 91 | 92 | function price1CumulativeLast() external view returns (uint); 93 | 94 | function kLast() external view returns (uint); 95 | 96 | function mint(address to) external returns (uint liquidity); 97 | 98 | function burn(address to) external returns (uint amount0, uint amount1); 99 | 100 | function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; 101 | 102 | function skim(address to) external; 103 | 104 | function sync() external; 105 | 106 | function initialize(address, address) external; 107 | } 108 | 109 | 110 | 111 | 112 | interface IUniswapV2Router01 { 113 | 114 | function factory() external pure returns (address); 115 | 116 | function WETH() external pure returns (address); 117 | 118 | function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); 119 | 120 | function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); 121 | 122 | function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); 123 | 124 | function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountToken, uint amountETH); 125 | 126 | function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); 127 | 128 | function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountETH); 129 | 130 | function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); 131 | 132 | function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); 133 | 134 | function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); 135 | 136 | function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); 137 | 138 | function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); 139 | 140 | function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); 141 | 142 | function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); 143 | 144 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); 145 | 146 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); 147 | 148 | function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); 149 | 150 | function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); 151 | 152 | } 153 | 154 | 155 | 156 | 157 | interface IUniswapV2Router02 is IUniswapV2Router01 { 158 | function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountETH); 159 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountETH); 160 | 161 | 162 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; 163 | function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; 164 | function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; 165 | 166 | } 167 | 168 | -------------------------------------------------------------------------------- /token_task/contracts/Taxes.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >0.6.0; 3 | 4 | import "./Liquidity.sol"; 5 | import "./libraries/PureMath.sol"; 6 | import "./libraries/USDT.sol"; 7 | 8 | /* 9 | * @title: $CIX, an ERC-20 standard token see README.md. 10 | * @author: Anthony (fps) https://github.com/0xfps. 11 | * @dev: 12 | * Liquidity Pool (UniswapV2Router) Address = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D. 13 | * USDT Contract Address Mainnet = 0x55d398326f99059ff775485246999027b3197955. 14 | * USDT Test Rinkeby = 0xa1Cba00d6e99f52B8cb5f867a6f2db0F3ad62276 ## Should be called with ether. 15 | * USDT Test Local = 0xd7Ca4e99F7C171B9ea2De80d3363c47009afaC5F ## Free I guess? Yep. On new deploy, get new address. 16 | */ 17 | contract Taxes { 18 | using PureMath for uint256; 19 | address[] internal _holders; 20 | // Dividends. 21 | mapping (address => uint) _dividends; 22 | // All taxes. 23 | uint usdt_rewards = 1.5 * 10; 24 | uint dev_rewards = 1.5 * 10; 25 | uint marketing_rewards = 1.5 * 10; 26 | uint environmental_causes_rewards = 1.5 * 10; 27 | uint liquidity_pool_rewards = 1 * 10; 28 | uint __decimals = 17; // This is set to 17, reference PureMath.sol set_perc() function. 29 | 30 | /* 31 | * @dev: 32 | * 33 | * {calculate_usdt_rewards()} calculates the usdt rewards and allocates it to every person on the `_allholders` array. 34 | * 35 | */ 36 | function calculate_usdt_rewards(uint amount) internal { 37 | // Tax 38 | uint usdt_tax = PureMath.set_perc(usdt_rewards, amount, 17); // This is set to 17, reference PureMath.sol set_perc() will return 18 dp. 39 | 40 | // Loops through the holders and their rewards and stores an additional tax for them. 41 | for (uint i = 0; i < _holders.length; i ++) { 42 | _dividends[_holders[i]] += usdt_tax; 43 | } 44 | } 45 | 46 | /* 47 | * @dev: 48 | * 49 | * {calculate_dev_rewards()}, {calculate_mkt_rewards()} and {calculate_env_rewards()} calculates the required rewards and returns the value. 50 | * 51 | */ 52 | function calculate_dev_rewards(uint amount) internal view returns(uint) { 53 | // Dev rewards. 54 | uint dev_tax = PureMath.set_perc(dev_rewards, amount, 17); // This is set to 17, reference PureMath.sol set_perc() will return 18 dp. 55 | return dev_tax; 56 | } 57 | 58 | function calculate_mkt_rewards(uint amount) internal view returns(uint) { 59 | // Marketing rewards. 60 | uint mkt_tax = PureMath.set_perc(marketing_rewards, amount, 17); // This is set to 17, reference PureMath.sol set_perc() will return 18 dp. 61 | return mkt_tax; 62 | } 63 | 64 | function calculate_env_rewards(uint amount) internal view returns(uint) { 65 | // Environmental causes rewards. 66 | uint env_tax = PureMath.set_perc(environmental_causes_rewards, amount, 17); // This is set to 17, reference PureMath.sol set_perc() will return 18 dp. 67 | return env_tax; 68 | } 69 | 70 | /* 71 | * @dev: 72 | * Withdrawals. HELP ME. 73 | */ 74 | function withdraw_usdt(uint amount) public { 75 | require(msg.sender != address(0), "$CIX - Error :: Caller address is a 0 address."); 76 | require (_dividends[msg.sender] >= amount, "$CIX - Error :: Cannot withdraw this amount."); 77 | USDT usdt = USDT(0x770861CdcdDF8319C6C86ef8EF91C4A922fc12aC); 78 | bool sent = usdt.transfer(msg.sender, amount); 79 | require(sent, "$CIX: Token not sent."); 80 | _dividends[msg.sender] = _dividends[msg.sender].sub(amount); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /token_task/scripts/__pycache__/deploy.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfps/my-solidity/e48ac755dbc1a173170d60839054c0bcae2a288e/token_task/scripts/__pycache__/deploy.cpython-310.pyc -------------------------------------------------------------------------------- /token_task/scripts/deploy.py: -------------------------------------------------------------------------------- 1 | from brownie import Cix, config, network, accounts 2 | 3 | def deploy(): 4 | print("Getting account....") 5 | account = get_account() 6 | print(f"Deployer account {account} confirmed!!!") 7 | print("Deploying contract Cix...") 8 | deploy_wallet = Cix.deploy({"from": account}, publish_source = False) 9 | print(f"Contract deployed successfully at {deploy_wallet.address}") 10 | 11 | with open("../Deployment Addresses.txt", "a+") as dep: 12 | dep.write("Cix => https://rinkeby.etherscan.io/address/"+deploy_wallet.address+"\n\n") 13 | 14 | 15 | def get_account(): 16 | if network.show_active() == "development": 17 | return accounts[0] 18 | else: 19 | return accounts.add(config['wallet']['from_key']) 20 | 21 | 22 | def main(): 23 | deploy() --------------------------------------------------------------------------------