├── gdao ├── README.md ├── contracts │ ├── GovernorToken.sol │ ├── SynLPToken.sol │ └── GovernorCrowdsale.sol └── flats │ ├── FlatGovernorToken.sol │ └── FlatSynLPToken.sol ├── merkle-distributor ├── index.html ├── setup │ ├── modifications │ │ ├── README.md │ │ ├── contract-modifications.md │ │ └── time-constraints.md │ ├── readme.md │ ├── installation.md │ └── merkle-root.md ├── tsconfig.json ├── scripts │ ├── result.json │ ├── generate-merkle-root.ts │ ├── to-kv-input.ts │ ├── verify-merkle-root.ts │ └── claims_example.json ├── SUMMARY.md ├── waffle.json ├── contracts │ ├── test │ │ └── TestERC20.sol │ ├── interfaces │ │ └── IMerkleDistributor.sol │ ├── MerkleDistributor_original.sol │ ├── MerkleDistributor.sol │ └── MerkleDistributor_flat.sol ├── README.md ├── src │ ├── balance-tree.ts │ ├── parse-balance-map.ts │ └── merkle-tree.ts ├── package.json ├── test │ └── MerkleDistributor.spec.ts └── LICENSE ├── swapico ├── migrations │ ├── 1_initial_migration.js │ └── 2_deploy_contracts.js ├── setup.sh ├── contracts │ ├── Migrations.sol │ ├── synLPToken.sol │ └── Swapico.sol ├── README.md ├── package.json ├── truffle-config.js ├── LICENSE └── flats │ ├── Swapico_flat.sol │ └── synLPToken_flat.sol ├── .gitignore ├── liquidity-mine ├── README.md ├── LICENSE └── contracts │ └── GovTreasurer.sol ├── LICENSE └── README.md /gdao/README.md: -------------------------------------------------------------------------------- 1 | ### GDAO -------------------------------------------------------------------------------- /merkle-distributor/index.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /swapico/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require("Migrations"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; -------------------------------------------------------------------------------- /merkle-distributor/setup/modifications/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | description: >- 3 | Overview of modifications over the original Uniswap Merkle Airdrop smart 4 | contract 5 | --- 6 | 7 | # Modifications 8 | 9 | -------------------------------------------------------------------------------- /merkle-distributor/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "strict": true, 6 | "esModuleInterop": true, 7 | "resolveJsonModule": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /merkle-distributor/scripts/result.json: -------------------------------------------------------------------------------- 1 | { 2 | "merkleRoot": "0xdefa96435aec82d201dbd2e5f050fb4e1fef5edac90ce1e03953f916a5e1132d", 3 | "tokenTotal": "0x64", 4 | "numDrops": 1, 5 | "claims": { "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f": { "index": 0, "amount": "0x64", "proof": [] } } 6 | } 7 | -------------------------------------------------------------------------------- /swapico/setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Deploy Contract 4 | truffle migrate --reset --network rinkeby 5 | 6 | # Verify Contract on Etherscan 7 | truffle run verify swapico --network rinkeby --license SPDX-License-Identifier 8 | 9 | # Flatten Contract 10 | ./node_modules/.bin/truffle-flattener contracts/swapico_flat.sol > flats/swapico_flat.sol -------------------------------------------------------------------------------- /swapico/migrations/2_deploy_contracts.js: -------------------------------------------------------------------------------- 1 | //const synLPToken = artifacts.require('synLPToken.sol') 2 | const swapico = artifacts.require('Swapico.sol') 3 | 4 | module.exports = async function(deployer) { 5 | 6 | // await deployer.deploy(synLPToken) 7 | // const synLPToken = await synLPToken.deployed() 8 | 9 | await deployer.deploy(swapico) 10 | const swapico = await swapico.deployed() 11 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | flattenedContracts 4 | 5 | # dependencies 6 | /node_modules 7 | /.pnp 8 | .pnp.js 9 | 10 | 11 | # testing 12 | /coverage 13 | 14 | # production 15 | /build 16 | app.zip 17 | 18 | # misc 19 | .DS_Store 20 | .env 21 | .env.local 22 | .env.development.local 23 | .env.test.local 24 | .env.production.local 25 | 26 | npm-debug.log* 27 | yarn-debug.log* 28 | yarn-error.log* -------------------------------------------------------------------------------- /merkle-distributor/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Table of contents 2 | 3 | * [README](README.md) 4 | 5 | ## Setup Guide 6 | 7 | * [README](setup/readme.md) 8 | * [Installation](setup/installation.md) 9 | * [Merkle Root](setup/merkle-root.md) 10 | * [Modifications](setup/modifications/README.md) 11 | * [New Addresses](setup/modifications/contract-modifications.md) 12 | * [Time Constraints](setup/modifications/time-constraints.md) 13 | 14 | -------------------------------------------------------------------------------- /liquidity-mine/README.md: -------------------------------------------------------------------------------- 1 | # GovTreasurer 2 | 3 | ## Mainnet Contracts 4 | 5 | - Token: https://etherscan.io/token/0x6b3595068778dd592e39a122f4f5a5cf09c90fe2 6 | - GovTreasurer: https://etherscan.io/address/0x4dac3e07316d2a31baabb252d89663dee8f76f09#code 7 | 8 | ## Rinkeby Contracts 9 | - Token https://rinkeby.etherscan.io/address/0x060dea069f4a0cf3f359152ec02f048ce9930686 10 | - GovTreasurer: https://rinkeby.etherscan.io/address/0xdf2a82d8a34f139f649000e43f60c921f769a947 11 | -------------------------------------------------------------------------------- /swapico/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.25 <= 0.7.0; 3 | 4 | contract Migrations { 5 | address public owner; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | if (msg.sender == owner) _; 10 | } 11 | 12 | constructor() public { 13 | owner = msg.sender; 14 | } 15 | 16 | function setCompleted(uint completed) public restricted { 17 | last_completed_migration = completed; 18 | } 19 | } -------------------------------------------------------------------------------- /merkle-distributor/scripts/generate-merkle-root.ts: -------------------------------------------------------------------------------- 1 | import { program } from 'commander' 2 | import fs from 'fs' 3 | import { parseBalanceMap } from '../src/parse-balance-map' 4 | 5 | program 6 | .version('0.0.0') 7 | .requiredOption( 8 | '-i, --input ', 9 | 'input JSON file location containing a map of account addresses to string balances' 10 | ) 11 | 12 | program.parse(process.argv) 13 | 14 | const json = JSON.parse(fs.readFileSync(program.input, { encoding: 'utf8' })) 15 | 16 | if (typeof json !== 'object') throw new Error('Invalid JSON') 17 | 18 | console.log(JSON.stringify(parseBalanceMap(json))) 19 | -------------------------------------------------------------------------------- /merkle-distributor/waffle.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerType": "solcjs", 3 | "compilerVersion": "./node_modules/solc", 4 | "outputType": "all", 5 | "compilerOptions": { 6 | "outputSelection": { 7 | "*": { 8 | "*": [ 9 | "evm.bytecode.object", 10 | "evm.deployedBytecode.object", 11 | "abi", 12 | "evm.bytecode.sourceMap", 13 | "evm.deployedBytecode.sourceMap", 14 | "metadata" 15 | ], 16 | "": ["ast"] 17 | } 18 | }, 19 | "evmVersion": "istanbul", 20 | "optimizer": { 21 | "enabled": true, 22 | "runs": 200 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /gdao/contracts/GovernorToken.sol: -------------------------------------------------------------------------------- 1 | // contracts/GovernorToken.sol 2 | // SPDX-License-Identifier: MIT 3 | pragma solidity ^0.5.0; 4 | 5 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/ERC20.sol"; 6 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/ERC20Burnable.sol"; 7 | 8 | contract GovernorToken is ERC20, ERC20Burnable { 9 | string public name; 10 | string public symbol; 11 | uint8 public decimals; 12 | constructor() public { 13 | name = "Governor"; 14 | symbol = "GDAO"; 15 | decimals = 18; 16 | _mint(msg.sender, 3000000*1e18); 17 | } 18 | } -------------------------------------------------------------------------------- /gdao/contracts/SynLPToken.sol: -------------------------------------------------------------------------------- 1 | // contracts/SynLPToken.sol 2 | // SPDX-License-Identifier: MIT 3 | pragma solidity ^0.5.0; 4 | 5 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/ERC20.sol"; 6 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/ERC20Burnable.sol"; 7 | 8 | contract SynLPToken2 is ERC20, ERC20Burnable { 9 | string public name; 10 | string public symbol; 11 | uint8 public decimals; 12 | constructor() public { 13 | name = "synthetic GDAO-ETH LP V2"; 14 | symbol = "sLP"; 15 | decimals = 18; 16 | _mint(msg.sender, 6710*1e18); 17 | } 18 | } -------------------------------------------------------------------------------- /swapico/contracts/synLPToken.sol: -------------------------------------------------------------------------------- 1 | 2 | // SPDX-License-Identifier: MIT 3 | pragma solidity =0.6.12; 4 | 5 | import '@openzeppelin/contracts/GSN/Context.sol'; 6 | import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; 7 | import '@openzeppelin/contracts/math/SafeMath.sol'; 8 | import '@openzeppelin/contracts/token/ERC20/ERC20.sol'; 9 | import '@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol'; 10 | 11 | contract SynLPToken is ERC20, ERC20Burnable { 12 | string public name; 13 | string public symbol; 14 | uint8 public decimals; 15 | constructor() public { 16 | name = "synthetic GDAO-ETH LP V2"; 17 | symbol = "sLP"; 18 | decimals = 18; 19 | _mint(msg.sender, 6710*1e18); 20 | } 21 | } -------------------------------------------------------------------------------- /merkle-distributor/contracts/test/TestERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.6.11; 3 | 4 | import '@openzeppelin/contracts/token/ERC20/ERC20.sol'; 5 | 6 | contract TestERC20 is ERC20 { 7 | constructor (string memory name_, string memory symbol_, uint amountToMint) ERC20(name_, symbol_) public { 8 | setBalance(msg.sender, amountToMint); 9 | } 10 | 11 | // sets the balance of the address 12 | // this mints/burns the amount depending on the current balance 13 | function setBalance(address to, uint amount) public { 14 | uint old = balanceOf(to); 15 | if (old < amount) { 16 | _mint(to, amount - old); 17 | } else if (old > amount) { 18 | _burn(to, old - amount); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /merkle-distributor/setup/readme.md: -------------------------------------------------------------------------------- 1 | --- 2 | description: >- 3 | Designed to explain the functionality of the Merkle Airdrop and walkthrough 4 | testing and deployment. 5 | --- 6 | 7 | # README 8 | 9 | ## What are the knowledge requirements? 10 | 11 | This guide is designed so that even the most novice user may understand and follow each of the steps required to install, test, verify, and successfully modify a Merkle Airdrop. 12 | 13 | ## What if I am still stuck? 14 | 15 | Feel free to reach out to me and I will gladly assist you, but understand I may also be busy with projects of my own, so you may not receive an immediate reply, but you will never be outright ignored. The best way to reach me is via the social links I have on my [Github](https://github.com/cryptounico). 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /merkle-distributor/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | description: FAQ and Setup Guide for the Governor DAO Merkle Airdrop 3 | --- 4 | 5 | # README 6 | 7 | ## What are the knowledge requirements? 8 | 9 | This guide is designed so that even the most novice user may understand and follow each of the steps required to install, test, verify, and successfully modify a Merkle Airdrop. 10 | 11 | ## What if I am still stuck? 12 | 13 | Feel free to reach out to me and I will gladly assist you, but understand I may also be busy with projects of my own, so you may not receive an immediate reply, but you will never be outright ignored. The best way to reach me is via the social links I have on my [Github](https://github.com/cryptounico). 14 | 15 | Credit: README.md and MerkleDistributor.sol created by [Uni](https://Learn-Solidity.com) 16 | 17 | -------------------------------------------------------------------------------- /swapico/README.md: -------------------------------------------------------------------------------- 1 | # Swapico 2 | 3 | - Simple, yet powerful implementation of a **swap contract** that enables you to recieve the ***authentico*** in exchange for your ***synthetico***. 4 | - Input the contract address and amount that you are willing to pay in exchange for an equivalent 1:1 purchase of the ***authentico*** token. 5 | - This contract also enables you to specify a **start time** (*inicio*), which allows you to build the front-end and include the production contract without worrying about swaps occuring sooner than anticipated. 6 | 7 | ## Smart Contracts 8 | - **Swapico.sol**: https://etherscan.io/address/0xcc23ef76b46ed576caa5a1481f4400d2543f8006#code 9 | - **GDAO-wETH sLP**: https://etherscan.io/address/0xCCED3780fba37761646962b2997d40B94De33954#code 10 | - **GDAO-wETH LP**: https://rinkeby.etherscan.io/address/0xb354b410071a12b5ccb28bd3275a44c6dc9dbc61#code 11 | -------------------------------------------------------------------------------- /swapico/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "swapico", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "dependencies": { 7 | "@openzeppelin/contracts": "^3.1.0", 8 | "@openzeppelin/test-helpers": "^0.5.6", 9 | "babel-polyfill": "6.26.0", 10 | "babel-preset-env": "1.7.0", 11 | "babel-preset-es2015": "6.24.1", 12 | "babel-preset-stage-2": "6.24.1", 13 | "babel-preset-stage-3": "6.24.1", 14 | "babel-register": "6.26.0", 15 | "dotenv": "6.2.0", 16 | "rimraf": "^3.0.0", 17 | "truffle": "^5.1.41", 18 | "truffle-flattener": "^1.4.4", 19 | "truffle-hdwallet-provider-privkey": "1.0.3", 20 | "truffle-plugin-verify": "^0.4.0", 21 | "web3": "1.0.0-beta.46" 22 | }, 23 | "scripts": { 24 | "install": "npm install", 25 | "migrate:rinkeby": "truffle migrate --reset --network rinkeby" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /merkle-distributor/setup/modifications/contract-modifications.md: -------------------------------------------------------------------------------- 1 | # New Addresses 2 | 3 | ### Adding: New Addresses 4 | 5 | Take note of the new addresses we will manually input upon deployment that are publicly viewable: 6 | 7 | {% code title="MerkleDistributor.sol" %} 8 | ```javascript 9 | contract MerkleDistributor is IMerkleDistributor { 10 | using SafeMath for uint256; 11 | address public immutable override token; 12 | bytes32 public immutable override merkleRoot; 13 | address public immutable override rewardsAddress; 14 | address public immutable override burnAddress; 15 | ``` 16 | {% endcode %} 17 | 18 | {% hint style="info" %} 19 | Note: in order to prevent burning tokens in error, the burnAddress is a multisig address in lieu of burning tokens directly from the contract itself. This requires trust from your community. 20 | {% endhint %} 21 | 22 | ### 23 | 24 | -------------------------------------------------------------------------------- /merkle-distributor/setup/modifications/time-constraints.md: -------------------------------------------------------------------------------- 1 | # Time Constraints 2 | 3 | ### Adding: Time Constraints 4 | 5 | The following uint256 values represent the predetermined start and end times associated with your contract. This is an optional step, but used in this instance to provide assurance that tokens will not remain in the contract forever as some will not ever claim for one reason or another. 6 | 7 | {% code title="MerkleDistributor.sol" %} 8 | ```csharp 9 | uint256 public immutable startTime; 10 | uint256 public immutable endTime; 11 | uint256 internal immutable secondsInaDay = 86400; 12 | ``` 13 | {% endcode %} 14 | 15 | {% hint style="info" %} 16 | Note: seconds in a day is defined as the literal seconds in a day, but this may be configured to match your testing environment, for example, suppose 20mins represents one full day. This would require a full day to equal X number of seconds, which is 1,200 seconds in 20min days. 17 | {% endhint %} 18 | 19 | -------------------------------------------------------------------------------- /swapico/truffle-config.js: -------------------------------------------------------------------------------- 1 | require('babel-register'); 2 | require('babel-polyfill'); 3 | require('dotenv').config(); 4 | const HDWalletProvider = require('truffle-hdwallet-provider-privkey'); 5 | const privateKeys = process.env.PRIVATE_KEYS || "" 6 | 7 | module.exports = { 8 | networks: { 9 | development: { 10 | host: "127.0.0.1", 11 | port: 7545, 12 | network_id: "*" 13 | }, 14 | rinkeby: { 15 | provider: function() { 16 | return new HDWalletProvider( 17 | privateKeys.split(','), // Array of account private keys 18 | `https://rinkeby.infura.io/v3/${process.env.INFURA_API_KEY}`// Url to an Ethereum Node 19 | ) 20 | }, 21 | gas: 5000000, 22 | gasPrice: 25000000000, 23 | network_id: 4 24 | } 25 | }, 26 | plugins: [ 27 | 'truffle-plugin-verify' 28 | ], 29 | api_keys: { 30 | etherscan: process.env.ETHERSCAN_API_KEY 31 | }, 32 | compilers: { 33 | solc: { 34 | version: "0.6.12" 35 | } 36 | } 37 | }; 38 | -------------------------------------------------------------------------------- /merkle-distributor/setup/installation.md: -------------------------------------------------------------------------------- 1 | --- 2 | description: Overview detailing how to setup up your work space for the merkle airdrop. 3 | --- 4 | 5 | # Installation 6 | 7 | Begin by opening your terminal and ensuring you have reviewed the repository prior to cloning. After you have reviewed the repository, **run the following CLI command**. 8 | 9 | ``` 10 | $ cd 11 | $ git clone https://github.com/CryptoUnico/merkle-distributor merkle 12 | ``` 13 | 14 | {% hint style="info" %} 15 | This will create a folder named merkle at the top of your directory tree. 16 | {% endhint %} 17 | 18 | ### Install Dependencies 19 | 20 | After cloning, navigate to the directory and install dependencies with yarn. 21 | 22 | ```bash 23 | $ cd merkle 24 | $ yarn 25 | ``` 26 | 27 | #### Note on Package.json 28 | 29 | The original scripts now include a shortcut for generating and verifying merkle roots. This may be found in the Package.json stored in the repository you cloned. Take a second to review and consider what else you may do to make working with the Merkle Airdrop repository easier for your use case. 30 | 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 uni 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /swapico/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 uni 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /liquidity-mine/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 GovernorDAO 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /merkle-distributor/setup/merkle-root.md: -------------------------------------------------------------------------------- 1 | # Merkle Root 2 | 3 | ### Generate Merkle Root 4 | 5 | Now, you have your dependencies, so you will be able to run a simple test to ensure the current inputs generate a merkle root you will then verify. **Run the following command to generate the merkle root.** 6 | 7 | ```bash 8 | $ yarn generate:example 9 | ``` 10 | 11 | {% hint style="info" %} 12 | For a quick primer on Cryptographic Hash Functions visit my post [here](https://soliditywiz.medium.com/cryptographic-hash-function-beaa2408260). 13 | {% endhint %} 14 | 15 | ### Test Merkle Root 16 | 17 | After generating the merkle root, be sure to save the results in a file named result\_example.json. This has already been done for you, but it is encouraged to practice doing this for yourself to ensure it works as you understand it should. After storing your results in a .json, **run the following command to verify that the root contains the claims** listed in the claims\_example.json. 18 | 19 | ```bash 20 | $ yarn verify:example 21 | ``` 22 | 23 | {% hint style="info" %} 24 | Recommend reviewing the structural design underlying Merkle Trees: [here](https://soliditywiz.medium.com/merkle-hash-trees-explained-ea384f2af7e8). 25 | {% endhint %} 26 | 27 | -------------------------------------------------------------------------------- /swapico/contracts/Swapico.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.6.12; 3 | import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; 4 | 5 | contract Swapico { 6 | 7 | address public immutable synthetico; 8 | address public immutable authentico; 9 | uint256 public immutable inicio; 10 | 11 | event purchased(address indexed _purchaser, uint256 indexed _tokens); 12 | 13 | constructor(address _synthetico, address _authentico, uint256 _inicio) public { 14 | synthetico = _synthetico; 15 | authentico = _authentico; 16 | inicio = _inicio; 17 | } 18 | 19 | function purchase(uint256 amount) public { 20 | require(block.timestamp >= inicio, 'purchase: too soon'); 21 | require(IERC20(synthetico).balanceOf(address(msg.sender)) >= amount, 'purchase: insufficient balance'); 22 | require(IERC20(authentico).balanceOf(address(this)) >= amount, 'purchase: insufficient liquidity'); 23 | _purchase(amount); 24 | } 25 | 26 | function _purchase(uint256 _amount) internal { 27 | IERC20(synthetico).burnFrom(msg.sender, _amount); 28 | IERC20(authentico).transfer(msg.sender, _amount); 29 | 30 | emit purchased(msg.sender, _amount); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /merkle-distributor/contracts/interfaces/IMerkleDistributor.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity >=0.5.0; 3 | 4 | // Allows anyone to claim a token if they exist in a merkle root. 5 | interface IMerkleDistributor { 6 | // Returns the address of the token distributed by this contract. 7 | function token() external view returns (address); 8 | // Returns the merkle root of the merkle tree containing account balances available to claim. 9 | function merkleRoot() external view returns (bytes32); 10 | // Returns the address of the rewards pool contributed to by this contract. 11 | function rewardsAddress() external view returns (address); 12 | // Returns the address of the burn pool contributed to by this contract. 13 | function burnAddress() external view returns (address); 14 | 15 | // Returns true if the index has been marked claimed. 16 | function isClaimed(uint256 index) external view returns (bool); 17 | // Claim the given amount of the token to the given address. Reverts if the inputs are invalid. 18 | function claim(uint256 index, address account, uint256 amount, bytes32[] calldata merkleProof) external; 19 | 20 | // This event is triggered whenever a call to #claim succeeds. 21 | event Claimed(uint256 index, address account, uint256 amount); 22 | } 23 | -------------------------------------------------------------------------------- /merkle-distributor/src/balance-tree.ts: -------------------------------------------------------------------------------- 1 | import MerkleTree from './merkle-tree' 2 | import { BigNumber, utils } from 'ethers' 3 | 4 | export default class BalanceTree { 5 | private readonly tree: MerkleTree 6 | constructor(balances: { account: string; amount: BigNumber }[]) { 7 | this.tree = new MerkleTree( 8 | balances.map(({ account, amount }, index) => { 9 | return BalanceTree.toNode(index, account, amount) 10 | }) 11 | ) 12 | } 13 | 14 | public static verifyProof( 15 | index: number | BigNumber, 16 | account: string, 17 | amount: BigNumber, 18 | proof: Buffer[], 19 | root: Buffer 20 | ): boolean { 21 | let pair = BalanceTree.toNode(index, account, amount) 22 | for (const item of proof) { 23 | pair = MerkleTree.combinedHash(pair, item) 24 | } 25 | 26 | return pair.equals(root) 27 | } 28 | 29 | // keccak256(abi.encode(index, account, amount)) 30 | public static toNode(index: number | BigNumber, account: string, amount: BigNumber): Buffer { 31 | return Buffer.from( 32 | utils.solidityKeccak256(['uint256', 'address', 'uint256'], [index, account, amount]).substr(2), 33 | 'hex' 34 | ) 35 | } 36 | 37 | public getHexRoot(): string { 38 | return this.tree.getHexRoot() 39 | } 40 | 41 | // returns the hex bytes32 values of the proof 42 | public getProof(index: number | BigNumber, account: string, amount: BigNumber): string[] { 43 | return this.tree.getHexProof(BalanceTree.toNode(index, account, amount)) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /merkle-distributor/scripts/to-kv-input.ts: -------------------------------------------------------------------------------- 1 | import { program } from 'commander' 2 | import fs from 'fs' 3 | import axios from 'axios' 4 | 5 | const BATCH_SIZE = 10_000 6 | 7 | program 8 | .version('0.0.0') 9 | .requiredOption('-i, --input ', 'input JSON file location containing a claims tree') 10 | .requiredOption('-c, --chain-id ', 'chain ID of the merkle kv root') 11 | .requiredOption('-t, --token ', 'Cloudflare API token') 12 | .requiredOption('-a, --account-identifier ', 'Cloudflare account identifier') 13 | .requiredOption('-n, --namespace-identifier ', 'Cloudflare KV namespace identifier') 14 | 15 | program.parse(process.argv) 16 | 17 | const json = JSON.parse(fs.readFileSync(program.input, { encoding: 'utf8' })) 18 | 19 | if (typeof json !== 'object') throw new Error('Invalid JSON') 20 | 21 | async function main() { 22 | const KV = Object.keys(json.claims).map((account) => { 23 | const claim = json.claims[account] 24 | return { 25 | key: `${program.chainId}:${account}`, 26 | value: JSON.stringify(claim), 27 | } 28 | }) 29 | 30 | let i = 0 31 | while (i < KV.length) { 32 | await axios 33 | .put( 34 | `https://api.cloudflare.com/client/v4/accounts/${program.accountIdentifier}/storage/kv/namespaces/${program.namespaceIdentifier}/bulk`, 35 | JSON.stringify(KV.slice(i, (i += BATCH_SIZE))), 36 | { 37 | maxBodyLength: Infinity, 38 | headers: { Authorization: `Bearer ${program.token}`, 'Content-Type': 'application/json' }, 39 | } 40 | ) 41 | .then((response) => { 42 | if (!response.data.success) { 43 | throw Error(response.data.errors) 44 | } 45 | }) 46 | 47 | console.log(`Uploaded ${i} records in total`) 48 | } 49 | } 50 | 51 | main() 52 | -------------------------------------------------------------------------------- /merkle-distributor/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@uniswap/merkle-distributor", 3 | "author": { 4 | "name": "Moody Salem" 5 | }, 6 | "description": "📦 A smart contract that distributes a balance of tokens according to a merkle root", 7 | "version": "1.0.1", 8 | "homepage": "https://uniswap.org", 9 | "keywords": [ 10 | "uniswap", 11 | "erc20" 12 | ], 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/Uniswap/merkle-distributor" 16 | }, 17 | "files": [ 18 | "build" 19 | ], 20 | "engines": { 21 | "node": ">=10" 22 | }, 23 | "devDependencies": { 24 | "@openzeppelin/contracts": "3.1.0", 25 | "@types/chai": "^4.2.6", 26 | "@types/mocha": "^5.2.7", 27 | "axios": "^0.20.0", 28 | "chai": "^4.2.0", 29 | "commander": "^6.1.0", 30 | "ethereum-waffle": "^3.0.0", 31 | "ethereumjs-util": "^7.0.4", 32 | "mocha": "^6.2.2", 33 | "prettier": "^2.0.5", 34 | "rimraf": "^3.0.0", 35 | "solc": "0.6.11", 36 | "ts-node": "^8.5.4", 37 | "typescript": "^3.7.3" 38 | }, 39 | "scripts": { 40 | "precompile": "rimraf ./build/", 41 | "compile": "waffle", 42 | "pretest": "yarn compile", 43 | "test": "mocha", 44 | 45 | "generate:example": "ts-node scripts/generate-merkle-root.ts --input scripts/claims_example.json", 46 | "generate:test": "ts-node scripts/generate-merkle-root.ts --input scripts/claims_test.json", 47 | "generate:prod": "ts-node scripts/generate-merkle-root.ts --input scripts/claims_prod.json", 48 | 49 | "verify:example": "ts-node scripts/verify-merkle-root.ts --input scripts/result_example.json", 50 | "verify:test": "ts-node scripts/verify-merkle-root.ts --input scripts/result_test.json", 51 | "verify:prod": "ts-node scripts/verify-merkle-root.ts --input scripts/result_prod.json", 52 | 53 | "prepublishOnly": "yarn test" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /merkle-distributor/contracts/MerkleDistributor_original.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.6.11; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | import "@openzeppelin/contracts/cryptography/MerkleProof.sol"; 6 | import "./interfaces/IMerkleDistributor.sol"; 7 | 8 | contract MerkleDistributor is IMerkleDistributor { 9 | address public immutable override token; 10 | bytes32 public immutable override merkleRoot; 11 | 12 | // This is a packed array of booleans. 13 | mapping(uint256 => uint256) private claimedBitMap; 14 | 15 | constructor(address token_, bytes32 merkleRoot_) public { 16 | token = token_; 17 | merkleRoot = merkleRoot_; 18 | } 19 | 20 | function isClaimed(uint256 index) public view override returns (bool) { 21 | uint256 claimedWordIndex = index / 256; 22 | uint256 claimedBitIndex = index % 256; 23 | uint256 claimedWord = claimedBitMap[claimedWordIndex]; 24 | uint256 mask = (1 << claimedBitIndex); 25 | return claimedWord & mask == mask; 26 | } 27 | 28 | function _setClaimed(uint256 index) private { 29 | uint256 claimedWordIndex = index / 256; 30 | uint256 claimedBitIndex = index % 256; 31 | claimedBitMap[claimedWordIndex] = claimedBitMap[claimedWordIndex] | (1 << claimedBitIndex); 32 | } 33 | 34 | function claim(uint256 index, address account, uint256 amount, bytes32[] calldata merkleProof) external override { 35 | require(!isClaimed(index), 'MerkleDistributor: Drop already claimed.'); 36 | 37 | // Verify the merkle proof. 38 | bytes32 node = keccak256(abi.encodePacked(index, account, amount)); 39 | require(MerkleProof.verify(merkleProof, merkleRoot, node), 'MerkleDistributor: Invalid proof.'); 40 | 41 | // Mark it claimed and send the token. 42 | _setClaimed(index); 43 | require(IERC20(token).transfer(account, amount), 'MerkleDistributor: Transfer failed.'); 44 | 45 | emit Claimed(index, account, amount); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GovernorDAO 2 | Official Repository for the Governor DAO cryptocurrency project. 3 | 4 | ## Q4 2020 - Present 5 | 6 | ### Governator: Swap any ERC-20 for the UNI-V2 pair with ETH 7 | - [GitHub Repo](https://github.com/CryptoUnico/Governator) | [Etherscan](https://etherscan.io/address/0x09e16ad071f4f80c02856275116cc772ba74b62c) 8 | - Enables you to swap any ERC-20 for its UNI-V2 pair with ETH. 9 | - Sends 2% of each transaction to the Governor Treasury as a tax. 10 | 11 | ### GovTreasurer (Liquidity Mine): GDAO Liquidity Fair Distribution with 2% Tax for Treasury 12 | - [GitHub Repo](https://github.com/CryptoUnico/govtreasurer) | [Etherscan](http://etherscan.io/address/0x4DaC3e07316D2A31baABb252D89663deE8F76f09#code) | [Front-End](https://mine.GovernorDAO.org) 13 | - Official Liquidity Mine for [GovernorDAO](https://GovernorDAO.org). 14 | - Slow drip, fair distribution of 1.2M GDAO governance tokens. 15 | - Accounts for roughly one-third of the GDAO total supply. 16 | 17 | ### Merkle Airdrop: Strategic Vested Airdrop with built-in HODL Incentives 18 | - [GitHub Repo](https://github.com/CryptoUnico/merkle-distributor) | [Etherscan](https://etherscan.io/address/0x7ea0f8bb2f01c197985c285e193dd5b8a69836c0#code) | [Front-End](https://airdrop.GovernorDAO.org) 19 | - Official [GovernorDAO](https://twitter.com/Governor_DAO) Merkle Airdrop Distribution for CBDAO Rug Pull survivors. 20 | - Gamefied elements to incentivize participants to claim at a later date. 21 | - Rules: on day one, 10% of the claim is available and increases 1% daily until 100% is reached. 22 | - Deflationary: 50% of forfeited tokens are burned forever, thus decreasing total max supply. 23 | 24 | ### Swapico: Swap the GDAO-ETH sLP for the UNI-V2 LP 25 | - [GitHub Repo](https://github.com/CryptoUnico/Swapico) | [Etherscan](https://etherscan.io/address/0xcc23ef76b46ed576caa5a1481f4400d2543f8006#code) | [Front-End](https://swap.governordao.org) 26 | - Swap one pre-determined token for another at a 1:1 ratio, though modifiable. 27 | - Used for GDAO sLP to LP conversion. 28 | 29 | ## Publications 30 | - [An Unruggable Airdrop](https://soliditywiz.medium.com/an-unruggable-airdrop-63c2ee9f242d) 31 | - [On the GovernorDAO Treasury](https://soliditywiz.medium.com/on-the-governor-dao-treasury-fund-13d3525d5682) 32 | - [How to: Develop Your Liquidity Mine](https://soliditywiz.medium.com/how-to-develop-your-liquidity-mine-9d47656fe678) 33 | - [Time (in) Smart Contract(s)](https://soliditywiz.medium.com/time-in-smart-contract-s-eec4a2fd108e) 34 | - [Cryptographic Hash Function](https://soliditywiz.medium.com/cryptographic-hash-function-beaa2408260) 35 | - [Merkle (Hash) Trees: Explained](https://soliditywiz.medium.com/merkle-hash-trees-explained-ea384f2af7e8) 36 | -------------------------------------------------------------------------------- /merkle-distributor/src/parse-balance-map.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber, utils } from 'ethers' 2 | import BalanceTree from './balance-tree' 3 | 4 | const { isAddress, getAddress } = utils 5 | 6 | // This is the blob that gets distributed and pinned to IPFS. 7 | // It is completely sufficient for recreating the entire merkle tree. 8 | // Anyone can verify that all air drops are included in the tree, 9 | // and the tree has no additional distributions. 10 | interface MerkleDistributorInfo { 11 | merkleRoot: string 12 | tokenTotal: string 13 | claims: { 14 | [account: string]: { 15 | index: number 16 | amount: string 17 | proof: string[] 18 | flags?: { 19 | [flag: string]: boolean 20 | } 21 | } 22 | } 23 | } 24 | 25 | type OldFormat = { [account: string]: number | string } 26 | type NewFormat = { address: string; earnings: string; reasons: string } 27 | 28 | export function parseBalanceMap(balances: OldFormat | NewFormat[]): MerkleDistributorInfo { 29 | // if balances are in an old format, process them 30 | const balancesInNewFormat: NewFormat[] = Array.isArray(balances) 31 | ? balances 32 | : Object.keys(balances).map( 33 | (account): NewFormat => ({ 34 | address: account, 35 | earnings: `0x${balances[account].toString(16)}`, 36 | reasons: '', 37 | }) 38 | ) 39 | 40 | const dataByAddress = balancesInNewFormat.reduce<{ 41 | [address: string]: { amount: BigNumber; flags?: { [flag: string]: boolean } } 42 | }>((memo, { address: account, earnings, reasons }) => { 43 | if (!isAddress(account)) { 44 | throw new Error(`Found invalid address: ${account}`) 45 | } 46 | const parsed = getAddress(account) 47 | if (memo[parsed]) throw new Error(`Duplicate address: ${parsed}`) 48 | const parsedNum = BigNumber.from(earnings) 49 | if (parsedNum.lte(0)) throw new Error(`Invalid amount for account: ${account}`) 50 | 51 | const flags = { 52 | isSOCKS: reasons.includes('socks'), 53 | isLP: reasons.includes('lp'), 54 | isUser: reasons.includes('user'), 55 | } 56 | 57 | memo[parsed] = { amount: parsedNum, ...(reasons === '' ? {} : { flags }) } 58 | return memo 59 | }, {}) 60 | 61 | const sortedAddresses = Object.keys(dataByAddress).sort() 62 | 63 | // construct a tree 64 | const tree = new BalanceTree( 65 | sortedAddresses.map((address) => ({ account: address, amount: dataByAddress[address].amount })) 66 | ) 67 | 68 | // generate claims 69 | const claims = sortedAddresses.reduce<{ 70 | [address: string]: { amount: string; index: number; proof: string[]; flags?: { [flag: string]: boolean } } 71 | }>((memo, address, index) => { 72 | const { amount, flags } = dataByAddress[address] 73 | memo[address] = { 74 | index, 75 | amount: amount.toHexString(), 76 | proof: tree.getProof(index, address, amount), 77 | ...(flags ? { flags } : {}), 78 | } 79 | return memo 80 | }, {}) 81 | 82 | const tokenTotal: BigNumber = sortedAddresses.reduce( 83 | (memo, key) => memo.add(dataByAddress[key].amount), 84 | BigNumber.from(0) 85 | ) 86 | 87 | return { 88 | merkleRoot: tree.getHexRoot(), 89 | tokenTotal: tokenTotal.toHexString(), 90 | claims, 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /merkle-distributor/src/merkle-tree.ts: -------------------------------------------------------------------------------- 1 | import { bufferToHex, keccak256 } from 'ethereumjs-util' 2 | 3 | export default class MerkleTree { 4 | private readonly elements: Buffer[] 5 | private readonly bufferElementPositionIndex: { [hexElement: string]: number } 6 | private readonly layers: Buffer[][] 7 | 8 | constructor(elements: Buffer[]) { 9 | this.elements = [...elements] 10 | // Sort elements 11 | this.elements.sort(Buffer.compare) 12 | // Deduplicate elements 13 | this.elements = MerkleTree.bufDedup(this.elements) 14 | 15 | this.bufferElementPositionIndex = this.elements.reduce<{ [hexElement: string]: number }>((memo, el, index) => { 16 | memo[bufferToHex(el)] = index 17 | return memo 18 | }, {}) 19 | 20 | // Create layers 21 | this.layers = this.getLayers(this.elements) 22 | } 23 | 24 | getLayers(elements: Buffer[]): Buffer[][] { 25 | if (elements.length === 0) { 26 | throw new Error('empty tree') 27 | } 28 | 29 | const layers = [] 30 | layers.push(elements) 31 | 32 | // Get next layer until we reach the root 33 | while (layers[layers.length - 1].length > 1) { 34 | layers.push(this.getNextLayer(layers[layers.length - 1])) 35 | } 36 | 37 | return layers 38 | } 39 | 40 | getNextLayer(elements: Buffer[]): Buffer[] { 41 | return elements.reduce((layer, el, idx, arr) => { 42 | if (idx % 2 === 0) { 43 | // Hash the current element with its pair element 44 | layer.push(MerkleTree.combinedHash(el, arr[idx + 1])) 45 | } 46 | 47 | return layer 48 | }, []) 49 | } 50 | 51 | static combinedHash(first: Buffer, second: Buffer): Buffer { 52 | if (!first) { 53 | return second 54 | } 55 | if (!second) { 56 | return first 57 | } 58 | 59 | return keccak256(MerkleTree.sortAndConcat(first, second)) 60 | } 61 | 62 | getRoot(): Buffer { 63 | return this.layers[this.layers.length - 1][0] 64 | } 65 | 66 | getHexRoot(): string { 67 | return bufferToHex(this.getRoot()) 68 | } 69 | 70 | getProof(el: Buffer) { 71 | let idx = this.bufferElementPositionIndex[bufferToHex(el)] 72 | 73 | if (typeof idx !== 'number') { 74 | throw new Error('Element does not exist in Merkle tree') 75 | } 76 | 77 | return this.layers.reduce((proof, layer) => { 78 | const pairElement = MerkleTree.getPairElement(idx, layer) 79 | 80 | if (pairElement) { 81 | proof.push(pairElement) 82 | } 83 | 84 | idx = Math.floor(idx / 2) 85 | 86 | return proof 87 | }, []) 88 | } 89 | 90 | getHexProof(el: Buffer): string[] { 91 | const proof = this.getProof(el) 92 | 93 | return MerkleTree.bufArrToHexArr(proof) 94 | } 95 | 96 | private static getPairElement(idx: number, layer: Buffer[]): Buffer | null { 97 | const pairIdx = idx % 2 === 0 ? idx + 1 : idx - 1 98 | 99 | if (pairIdx < layer.length) { 100 | return layer[pairIdx] 101 | } else { 102 | return null 103 | } 104 | } 105 | 106 | private static bufDedup(elements: Buffer[]): Buffer[] { 107 | return elements.filter((el, idx) => { 108 | return idx === 0 || !elements[idx - 1].equals(el) 109 | }) 110 | } 111 | 112 | private static bufArrToHexArr(arr: Buffer[]): string[] { 113 | if (arr.some((el) => !Buffer.isBuffer(el))) { 114 | throw new Error('Array is not an array of buffers') 115 | } 116 | 117 | return arr.map((el) => '0x' + el.toString('hex')) 118 | } 119 | 120 | private static sortAndConcat(...args: Buffer[]): Buffer { 121 | return Buffer.concat([...args].sort(Buffer.compare)) 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /merkle-distributor/scripts/verify-merkle-root.ts: -------------------------------------------------------------------------------- 1 | import { program } from 'commander' 2 | import fs from 'fs' 3 | import { BigNumber, utils } from 'ethers' 4 | 5 | program 6 | .version('0.0.0') 7 | .requiredOption( 8 | '-i, --input ', 9 | 'input JSON file location containing the merkle proofs for each account and the merkle root' 10 | ) 11 | 12 | program.parse(process.argv) 13 | const json = JSON.parse(fs.readFileSync(program.input, { encoding: 'utf8' })) 14 | 15 | const combinedHash = (first: Buffer, second: Buffer): Buffer => { 16 | if (!first) { 17 | return second 18 | } 19 | if (!second) { 20 | return first 21 | } 22 | 23 | return Buffer.from( 24 | utils.solidityKeccak256(['bytes32', 'bytes32'], [first, second].sort(Buffer.compare)).slice(2), 25 | 'hex' 26 | ) 27 | } 28 | 29 | const toNode = (index: number | BigNumber, account: string, amount: BigNumber): Buffer => { 30 | const pairHex = utils.solidityKeccak256(['uint256', 'address', 'uint256'], [index, account, amount]) 31 | return Buffer.from(pairHex.slice(2), 'hex') 32 | } 33 | 34 | const verifyProof = ( 35 | index: number | BigNumber, 36 | account: string, 37 | amount: BigNumber, 38 | proof: Buffer[], 39 | root: Buffer 40 | ): boolean => { 41 | let pair = toNode(index, account, amount) 42 | for (const item of proof) { 43 | pair = combinedHash(pair, item) 44 | } 45 | 46 | return pair.equals(root) 47 | } 48 | 49 | const getNextLayer = (elements: Buffer[]): Buffer[] => { 50 | return elements.reduce((layer, el, idx, arr) => { 51 | if (idx % 2 === 0) { 52 | // Hash the current element with its pair element 53 | layer.push(combinedHash(el, arr[idx + 1])) 54 | } 55 | 56 | return layer 57 | }, []) 58 | } 59 | 60 | const getRoot = (balances: { account: string; amount: BigNumber; index: number }[]): Buffer => { 61 | let nodes = balances 62 | .map(({ account, amount, index }) => toNode(index, account, amount)) 63 | // sort by lexicographical order 64 | .sort(Buffer.compare) 65 | 66 | // deduplicate any eleents 67 | nodes = nodes.filter((el, idx) => { 68 | return idx === 0 || !nodes[idx - 1].equals(el) 69 | }) 70 | 71 | const layers = [] 72 | layers.push(nodes) 73 | 74 | // Get next layer until we reach the root 75 | while (layers[layers.length - 1].length > 1) { 76 | layers.push(getNextLayer(layers[layers.length - 1])) 77 | } 78 | 79 | return layers[layers.length - 1][0] 80 | } 81 | 82 | if (typeof json !== 'object') throw new Error('Invalid JSON') 83 | 84 | const merkleRootHex = json.merkleRoot 85 | const merkleRoot = Buffer.from(merkleRootHex.slice(2), 'hex') 86 | 87 | let balances: { index: number; account: string; amount: BigNumber }[] = [] 88 | let valid = true 89 | 90 | Object.keys(json.claims).forEach((address) => { 91 | const claim = json.claims[address] 92 | const proof = claim.proof.map((p: string) => Buffer.from(p.slice(2), 'hex')) 93 | balances.push({ index: claim.index, account: address, amount: BigNumber.from(claim.amount) }) 94 | if (verifyProof(claim.index, address, claim.amount, proof, merkleRoot)) { 95 | console.log('Verified proof for', claim.index, address) 96 | } else { 97 | console.log('Verification for', address, 'failed') 98 | valid = false 99 | } 100 | }) 101 | 102 | if (!valid) { 103 | console.error('Failed validation for 1 or more proofs') 104 | process.exit(1) 105 | } 106 | console.log('Done!') 107 | 108 | // Root 109 | const root = getRoot(balances).toString('hex') 110 | console.log('Reconstructed merkle root', root) 111 | console.log('Root matches the one read from the JSON?', root === merkleRootHex.slice(2)) 112 | -------------------------------------------------------------------------------- /merkle-distributor/contracts/MerkleDistributor.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.6.11; 3 | 4 | import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; 5 | import '@openzeppelin/contracts/math/SafeMath.sol'; 6 | import '@openzeppelin/contracts/cryptography/MerkleProof.sol'; 7 | import './interfaces/IMerkleDistributor.sol'; 8 | 9 | contract MerkleDistributor is IMerkleDistributor { 10 | using SafeMath for uint256; 11 | address public immutable override token; 12 | bytes32 public immutable override merkleRoot; 13 | address public immutable override rewardsAddress; 14 | address public immutable override burnAddress; 15 | 16 | // Packed array of booleans. 17 | mapping(uint256 => uint256) private claimedBitMap; 18 | address deployer; 19 | 20 | uint256 public immutable startTime; 21 | uint256 public immutable endTime; 22 | uint256 internal immutable secondsInaDay = 86400; 23 | 24 | constructor(address token_, bytes32 merkleRoot_, address rewardsAddress_, address burnAddress_, uint256 startTime_, uint256 endTime_) public { 25 | token = token_; 26 | merkleRoot = merkleRoot_; 27 | rewardsAddress = rewardsAddress_; 28 | burnAddress = burnAddress_; 29 | deployer = msg.sender; // the deployer address 30 | startTime = startTime_; 31 | endTime = endTime_; 32 | } 33 | 34 | function isClaimed(uint256 index) public view override returns (bool) { 35 | uint256 claimedWordIndex = index / 256; 36 | uint256 claimedBitIndex = index % 256; 37 | uint256 claimedWord = claimedBitMap[claimedWordIndex]; 38 | uint256 mask = (1 << claimedBitIndex); 39 | return claimedWord & mask == mask; 40 | } 41 | 42 | function _setClaimed(uint256 index) private { 43 | uint256 claimedWordIndex = index / 256; 44 | uint256 claimedBitIndex = index % 256; 45 | claimedBitMap[claimedWordIndex] = claimedBitMap[claimedWordIndex] | (1 << claimedBitIndex); 46 | } 47 | 48 | function claim(uint256 index, address account, uint256 amount, bytes32[] calldata merkleProof) external override { 49 | require(msg.sender == account, 'MerkleDistributor: Only account may withdraw'); // self-request only 50 | require(!isClaimed(index), 'MerkleDistributor: Drop already claimed.'); 51 | 52 | // VERIFY | MERKLE PROOF 53 | bytes32 node = keccak256(abi.encodePacked(index, account, amount)); 54 | require(MerkleProof.verify(merkleProof, merkleRoot, node), 'MerkleDistributor: Invalid proof.'); 55 | 56 | // CLAIM AND SEND | TOKEN TO ACCOUNT 57 | _setClaimed(index); 58 | uint256 duraTime = block.timestamp.sub(startTime); 59 | 60 | require(block.timestamp >= startTime, 'MerkleDistributor: Too soon'); // [P] Start (unix): 1607990400 | Tuesday, December 15th, 2020 @ 12:00AM GMT 61 | require(block.timestamp <= endTime, 'MerkleDistributor: Too late'); // [P] End (unix): 1616630400 | Thursday, March 25th, 2021 @ 12:00AM GMT 62 | 63 | uint256 duraDays = duraTime.div(secondsInaDay); 64 | require(duraDays <= 100, 'MerkleDistributor: Too late'); // Check days 65 | 66 | uint256 claimableDays = duraDays >= 90 ? 90 : duraDays; // limits claimable days (90) 67 | uint256 claimableAmount = amount.mul(claimableDays.add(10)).div(100); // 10% + 1% daily 68 | require(claimableAmount <= amount, 'MerkleDistributor: Slow your roll'); // gem insurance 69 | uint256 forfeitedAmount = amount.sub(claimableAmount); 70 | 71 | require(IERC20(token).transfer(account, claimableAmount), 'MerkleDistributor: Transfer to Account failed.'); 72 | require(IERC20(token).transfer(rewardsAddress, forfeitedAmount.div(2)), 'MerkleDistributor: Transfer to rewardAddress failed.'); 73 | require(IERC20(token).transfer(burnAddress, forfeitedAmount.div(2)), 'MerkleDistributor: Transfer to burnAddress failed.'); 74 | 75 | emit Claimed(index, account, amount); 76 | } 77 | 78 | function collectDust(address _token, uint256 _amount) external { 79 | require(msg.sender == deployer, "!deployer"); 80 | require(_token != token, "!token"); 81 | if (_token == address(0)) { // token address(0) = ETH 82 | payable(deployer).transfer(_amount); 83 | } else { 84 | IERC20(_token).transfer(deployer, _amount); 85 | } 86 | } 87 | 88 | function collectUnclaimed(uint256 amount) external{ 89 | require(msg.sender == deployer, 'MerkleDistributor: not deployer'); 90 | require(IERC20(token).transfer(deployer, amount), 'MerkleDistributor: collectUnclaimed failed.'); 91 | } 92 | 93 | function dev(address _deployer) public { 94 | require(msg.sender == deployer, 'dev: wut?'); 95 | deployer = _deployer; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /gdao/contracts/GovernorCrowdsale.sol: -------------------------------------------------------------------------------- 1 | // contracts/GovernorCrowdsale.sol 2 | // SPDX-License-Identifier: MIT 3 | pragma solidity ^0.5.0; 4 | 5 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/crowdsale/validation/CappedCrowdsale.sol"; 6 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/access/roles/CapperRole.sol"; 7 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/crowdsale/validation/TimedCrowdsale.sol"; 8 | 9 | 10 | contract GovernorCrowdsale is CappedCrowdsale, TimedCrowdsale, CapperRole { 11 | 12 | using SafeMath for uint256; 13 | 14 | mapping(address => uint256) private _contributions; 15 | mapping(address => uint256) private _caps; 16 | mapping(address => bool) private whitelist; 17 | 18 | uint256 private _individualDefaultCap; 19 | 20 | constructor ( 21 | uint256 rate, 22 | address payable wallet, 23 | IERC20 token, 24 | uint256 openingTime, 25 | uint256 closingTime, 26 | uint256 cap, 27 | uint256 individualCap 28 | ) 29 | public 30 | Crowdsale(rate, wallet, token) 31 | TimedCrowdsale(openingTime, closingTime) 32 | CappedCrowdsale(cap) 33 | { 34 | _individualDefaultCap = individualCap; 35 | } 36 | 37 | /** 38 | * @dev Sets a specific beneficiary's maximum contribution. 39 | * @param beneficiary Address to be capped 40 | * @param cap Wei limit for individual contribution 41 | */ 42 | function setCap(address beneficiary, uint256 cap) external onlyCapper { 43 | _caps[beneficiary] = cap; 44 | } 45 | 46 | /** 47 | * @dev Adds addresseto whitelist. 48 | * @param beneficiary Address list to whitelist 49 | */ 50 | function addWhitelist(address beneficiary) external onlyCapper{ 51 | whitelist[beneficiary] = true; 52 | } 53 | 54 | /** 55 | * @dev Adds multipled addresses to whitelist. 56 | * @param beneficiary Address list to whitelist 57 | */ 58 | function addManyWhitelist(address[] calldata beneficiary) external onlyCapper{ 59 | for (uint i = 0; i < beneficiary.length; i++){ 60 | whitelist[beneficiary[i]] = true; 61 | } 62 | } 63 | 64 | /** 65 | * @dev Removes address from whitelist. 66 | * @param beneficiary Address to remove from whitelist 67 | */ 68 | function removeWhitelist(address beneficiary) external onlyCapper{ 69 | whitelist[beneficiary] = false; 70 | } 71 | 72 | /** 73 | * @dev Returns if address is whitelisted. 74 | * @param beneficiary Address whose whitelist status is checked 75 | * @return true if whitelisted, false if not 76 | */ 77 | function isWhitelisted(address beneficiary) public view returns (bool){ 78 | return whitelist[beneficiary] == true; 79 | } 80 | 81 | /** 82 | * @dev Returns the cap of a specific beneficiary. 83 | * @param beneficiary Address whose cap is to be checked 84 | * @return Current cap for individual beneficiary 85 | */ 86 | function getCap(address beneficiary) public view returns (uint256) { 87 | uint256 cap = _caps[beneficiary]; 88 | if (cap == 0) { 89 | cap = _individualDefaultCap; 90 | } 91 | return cap; 92 | } 93 | 94 | /** 95 | * @dev Returns the amount contributed so far by a specific beneficiary. 96 | * @param beneficiary Address of contributor 97 | * @return Beneficiary contribution so far 98 | */ 99 | function getContribution(address beneficiary) public view returns (uint256) { 100 | return _contributions[beneficiary]; 101 | } 102 | 103 | /** 104 | * @dev Extend parent behavior requiring purchase to respect the beneficiary's funding cap. 105 | * @param beneficiary Token purchaser 106 | * @param weiAmount Amount of wei contributed 107 | */ 108 | function _preValidatePurchase(address beneficiary, uint256 weiAmount) internal view { 109 | super._preValidatePurchase(beneficiary, weiAmount); 110 | // solhint-disable-next-line max-line-length 111 | require(whitelist[beneficiary], "Governor LGE: Address not whitelisted"); 112 | require(_contributions[beneficiary].add(weiAmount) <= getCap(beneficiary), "Governor LGE: beneficiary's cap exceeded"); 113 | } 114 | 115 | /** 116 | * @dev Extend parent behavior to update beneficiary contributions. 117 | * @param beneficiary Token purchaser 118 | * @param weiAmount Amount of wei contributed 119 | */ 120 | function _updatePurchasingState(address beneficiary, uint256 weiAmount) internal { 121 | super._updatePurchasingState(beneficiary, weiAmount); 122 | _contributions[beneficiary] = _contributions[beneficiary].add(weiAmount); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /merkle-distributor/scripts/claims_example.json: -------------------------------------------------------------------------------- 1 | { 2 | "0xF3c6F5F265F503f53EAD8aae90FC257A5aa49AC1": 1, 3 | "0xB9CcDD7Bedb7157798e10Ff06C7F10e0F37C6BdD": 2, 4 | "0xf94DbB18cc2a7852C9CEd052393d517408E8C20C": 3, 5 | "0xf0591a60b8dBa2420408Acc5eDFA4f8A15d87308": 4, 6 | "0x6A2dE67981CbE91209c1046D67eF7a45631d0666": 5, 7 | "0x7C262baf13794f54e3514539c411f92716996C38": 6, 8 | "0x57E7c6B647C004CFB7A38E08fDDef09Af5Ea55eD": 7, 9 | "0x05fc93DeFFFe436822100E795F376228470FB514": 8, 10 | "0x6b6C7139B48156d7EC90eD4c55C56bDFCB1C19D2": 9, 11 | "0x7D13f07889F04a593a3E12f5d3f8Bf850d07465B": 10, 12 | "0xb86739476a4820FcC39Ff1C413d9af0b96c1589F": 11, 13 | "0xf66705E0Ae4e5DfC02b2633356f5305662F00d3b": 12, 14 | "0xC7AA922f0823DeE2eD721E61ebCCF2F9596017Fb": 13, 15 | "0x6E9Ead46916950088E236A77bb7b6309170827CA": 14, 16 | "0x656231095A6700620062B308C900E124461C48B6": 15, 17 | "0xCb73bE1851f2133895C05D408666475bA8Da351e": 16, 18 | "0x6FCBCB45deE6649450932f7FF142C7c434CED9a6": 17, 19 | "0xB34bf945E5a5698087820812e9CCBA0686D2a783": 18, 20 | "0x31f161a781a30AB4bF4Bf11175e3098204FB5235": 19, 21 | "0xde03a8041B40FF95F7F6b6ca0d1Da80fbBD07925": 20, 22 | "0xdc7B752019AC5eFA067Bd3dE17Fc2D2c7C8d881e": 21, 23 | "0xcB4A9ae3d5C4c9BF3c688d387230559018FB90C3": 22, 24 | "0x97Ac383e64d5a1A2A08c646C87B6e0546F7c164B": 23, 25 | "0xc0B7C64d370A9ffcFb9ef675809126c5cAfA9619": 24, 26 | "0xC910240362A5dda9e6cE8fAc86C329864d9Da15d": 25, 27 | "0x7e72833a9D8Da5458470f2B226f1c095ef335e86": 26, 28 | "0x40DeF14b2793e99f1f453FbD98A0f251a1D19f4f": 27, 29 | "0xBC61c73CFc191321DA837def848784c002279a01": 28, 30 | "0x32Cc3F29cde7ac9c000FEbf0D8F28B94F1A34441": 29, 31 | "0x538F43872aC14d3130721Df4F02a3Ff05053A2d9": 30, 32 | "0xDE78e3462c9F976257E5E4Ed821BE7B306B23450": 31, 33 | "0xF1079DD1048A65cA9f9153246164758203d1aEd5": 32, 34 | "0xAb7Fb5958785b20bdccd2A65d15F139B60080fAc": 33, 35 | "0xc6b467aCAa5B07b8182749524385B79DBb909B14": 34, 36 | "0xE7fA80757FeAb870E0bF3b3dc8d4647f403A65ac": 35, 37 | "0x72381936D8e22a52F9a6ea62e23628084085D05b": 36, 38 | "0x3fC98BAD7384a354f8b083Fc5A7D621DF5fB9F41": 37, 39 | "0x5e471D67A610f541B63a8789A9BE1F0fAcd9E244": 38, 40 | "0x5a693Fc88b80Bd7e57f676Bd5e0945995f68bC47": 39, 41 | "0x69eA0b9B0b489B87E061e3e85886D668b24157Ad": 40, 42 | "0x7D0Fe663D9488F6793D813e51EC1DC600F289ad3": 41, 43 | "0x162F49fE6F365d04Db07F77377699aeFE2E8A2cf": 42, 44 | "0x8A1F2B46A35D10F0EafbE6c7f0671d8DB847dcA2": 43, 45 | "0x4aA6E2Fe3f306CB777dFeA344daaAd33eB50f972": 44, 46 | "0x1fCBa490902B2BD44ba98359C7075e2C8a2b9F15": 45, 47 | "0xdd1f7Ea709BD594D834411AE22D81a5B6a91008F": 46, 48 | "0x406b7968735b79688C6694634f2Ef5CF01c386F5": 47, 49 | "0x7152dc7a0eC646A7bCD3b00EF4Ca984E337da2B3": 48, 50 | "0xdf9424b7563A00386217471cfAC8944185505c56": 49, 51 | "0xaDF30D969b396DFC5035Cb3921034Bfb86CC055d": 50, 52 | "0xf970e1f7e89a57485E139F9EB4652181Ef270515": 51, 53 | "0xBd8BcBdF78205590FD576acaf110d70069eE7125": 52, 54 | "0xd7663Ca75082939012A9b5DCaFaDABEA51352F70": 53, 55 | "0x75662678a74C6aD63501519F656CE4Db04e1EF49": 54, 56 | "0xC1f94BCA2146B462685FC04Bf10f8b8CB7a305a3": 55, 57 | "0x7DD3A4cCf156475AE927E9aedc91E9f33AABc79d": 56, 58 | "0x85c5EE48A6687c9D903052a22f5764Bed2B4A6A8": 57, 59 | "0x73f24B3cB7FDAf629d2DC44f67ADaA99005719B0": 58, 60 | "0x9Cce64165E28dEA01a8b9c977F4dbD9D791EbcFf": 59, 61 | "0xcB667d9F540E721858e77E6667e281Aa6fFD5C17": 60, 62 | "0x0f39bceBE74751D89c37a2671DE0c750b71cA152": 61, 63 | "0xC0CDEE637cd0Ef7Ef7ab2696ffADc9C78F4daa0B": 62, 64 | "0x0cF605Ad65B1A541Ca6390606F944D176D5B9950": 63, 65 | "0x614de94D2E18c174bc0155EFef55bAa9cB55bAf2": 64, 66 | "0xa47A8fa265bf540184fA3499566761A608Be84EE": 65, 67 | "0xD2ED9f212c6f5d127757fA700cc55235F5cBc167": 66, 68 | "0xfA4563612C9De62302364ee8042635e44c8327fF": 67, 69 | "0x0350D208F3D94Af84724e437fAa7ebe5A3C35aC7": 68, 70 | "0x31de7522f31322081516703F78ce8eA128d9D6f7": 69, 71 | "0x3e51a90d40F8dC43d2b8720B3671aa208b0316ac": 70, 72 | "0x9BDFE65726326c104a302B172e49c4946E481306": 71, 73 | "0xe7B6bdA3990D0F6892cB1c37F4f2867a8Df4Fe5e": 72, 74 | "0x42B6cC78074eF1C5eC4AEe844B4B9c27b199831F": 73, 75 | "0x1E5eF4320142B6721C27846c9Ab4D6F0a0aFD2CE": 74, 76 | "0xA998c01B7c9674490480ec68bCf27C836CF9B495": 75, 77 | "0xa087344Bc4A05D2885aa9531ae6694e0C5dEb728": 76, 78 | "0x8874a8B06bd074953a9b22CaaC0Ce3bCf1260fB4": 77, 79 | "0x8943b759EaAa0e51b93ddB12B19e9EB71A361c69": 78, 80 | "0x4540e3Ef6dC7a420cd44767F98EF15BEEA28606D": 79, 81 | "0x4d9366B189AA78B9764Bd50B22F9398ABB4AcFbD": 80, 82 | "0x250fC1677986e6c3CEb348a378919f5b0Eb487ea": 81, 83 | "0x1668395E2FDEC223E175111ff8bDce4180A3B680": 82, 84 | "0x904dac1641aC5DAB76B7b2B2AB2779E98ac6BC74": 83, 85 | "0x169D0Cc3e36D3C9253Dd8418421Af5F84a75EC76": 84, 86 | "0x012ed55a0876Ea9e58277197DC14CbA47571CE28": 85, 87 | "0xc07b1400fB950253fbfC5484601036f18c8A91CC": 86, 88 | "0x3741c4751bBff7ba5D58BDA8F1c25Cb71b6b95D2": 87, 89 | "0x01dC7F8C928CeA27D8fF928363111c291bEB20b1": 88, 90 | "0x41560a0CC92C4267614721140a031aE20051Bb65": 89, 91 | "0xF1d322d48E47eb4A806bAB843B5C79Af641bb8cD": 90, 92 | "0x332BC77780057942cAa2c7bad21a04E91B5Ed687": 91, 93 | "0x8519E69FfaF870479534b362ce34F666533aE758": 92, 94 | "0xBF134F1BD442c77F01d4784D991F3c191ce700cf": 93, 95 | "0xb7649E4000AD4748dc2907eCdcAC4ae3d59da0D5": 94, 96 | "0x84664986ad6D1237010be3BFC0F88555edc6987f": 95, 97 | "0x983a9ed0e4A274314231BFce58Ec973f0D298c9d": 96, 98 | "0x9F0A64c6956D7205E883ae8A3C19577f1cadD78F": 97, 99 | "0xB96cE59522314ACB1502Dc8d3e192995e36439c1": 98, 100 | "0x5A553d59435Df0688fd5dEa1aa66C7430541ffB3": 99 101 | } 102 | -------------------------------------------------------------------------------- /swapico/flats/Swapico_flat.sol: -------------------------------------------------------------------------------- 1 | /** 2 | *Submitted for verification at Etherscan.io on 2020-12-20 3 | */ 4 | 5 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 7 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 8 | //////////////////////////////////////.////////////////////////////////.//////////////////////////////////// 9 | ///////////////////////////////////.@.//////////////////////////////////.@.///////////////////////////////// 10 | ////////////////////////////////.@@.//////////////////////////////////////.@@.////////////////////////////// 11 | /////////////////////////////..@@@.////////////////////////////////////////.@@@../////////////////////////// 12 | ///////////////////////////.@@@@@.//////////////////////////////////////////.@@@@@.///////////////////////// 13 | /////////////////////////.@@@@@@@////////////////////////////////////////////@@@@@@@./////////////////////// 14 | ////////////////////////.@@@@@@@.////////////////////////////////////////////.@@@@@@@.////////////////////// 15 | //////////////////..///.@@@@@@@@//////////////////////////////////////////////@@@@@@@@.///..//////////////// 16 | ////////////////.@@.//.@@@@@@@@@//////////////////////////////////////////////@@@@@@@@@.//.@@.////////////// 17 | ///////////////@@@@.//@@@@@@@@@.//////////////////////////////////////////////.@@@@@@@@@//@@@@@///////////// 18 | //////////////@@@@@@//@@@@@@@@@.//////////////////////////////////////////////.@@@@@@@@@//@@@@@@//////////// 19 | /////////////@@@@@@@./@@@@@@@@@@//////////////////////////////////////////////@@@@@@@@@./.@@@@@@@/////////// 20 | /////////////@@@@@@@@//@@@@@@@@@.////////////////////////////////////////////.@@@@@@@@@//@@@@@@@@/////////// 21 | /////////////@@@@@@@@.//.@@@@@@@@.//////////////////////////////////////////@@@@@@@@@.//.@@@@@@@@/////////// 22 | /////////////@@@@@@@@@///.@@@@@@@@@.////////.//////////////////////////////@@@@@@@@@.///@@@@@@@@@/////////// 23 | /////////////.@@@@@@@@@///..@@@@@@@.////////.@.///////////////////////////.@@@@@@@.////@@@@@@@@@./////////// 24 | //////////////.@@@@@@@@@.////.@@@@///////////.@@.//////////////////////////.@@@@.////.@@@@@@@@@.//////////// 25 | //////////.////.@@@@@@@@@@./////./////////////.@@@@..////////////////////////./////.@@@@@@@@@@.///..//////// 26 | //////////@@.///.@@@@@@@@@@@.//////////////////.@@@@@@@@@@./////////////////////..@@@@@@@@@@.///.@@.//////// 27 | //////////@@@@.///.@@@@@@@@@@@@.////////////////.@@@@@@@@@@@..///////////////.@@@@@@@@@@@@@.//.@@@@.//////// 28 | //////////.@@@@@@.///.@@@@@@@@@@@.///////////////.@@@@@@@@@@@@./////////////.@@@@@@@@@@@.//.@@@@@@@.//////// 29 | //////////.@@@@@@@@.////.@@@@@@@@@.///////////////@@@@@@@@@...@////////////.@@@@@@@@@.//..@@@@@@@@@.//////// 30 | //////////.@@@@@@@@@@@..////..@@@@@@./////////////@@@@@@@@@ /////////////.@@@@@@..///..@@@@@@@@@@@.///////// 31 | ///////////.@@@@@@@@@@@@@@..//////.....///////////@@@@@@@@@.///////////...../////..@@@@@@@@@@@@@@@////////// 32 | ////////////.@@@@@@@@@@@@@@@@@@....///////////////@@@@@@@@@.///////////////...@@@@@@@@@@@@@@@@@@@.////////// 33 | /////////////.@@@@@@@@@@@@@@@@@@@@@@@@@@@..///////@@@@@@@@@@//////....@@@@@@@@@@@@@@@@@@@@@@@@@@./////////// 34 | //////////////.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.///.@@@@@@@@@@/////@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@///////////// 35 | ////////////////.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@///@@@@@@@@@@@.///.@@@@@@@@@@@@@@@@@@@@@@@@@@@@.////////////// 36 | //////////////////.@@@@@@@@@@@@@@@@@@@@@@@@@@@@/@@@@@@@@@@@@@./.@@@@@@@@@@@@@@@@@@@@@@@@@@@.//////////////// 37 | ////////////////////.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..////////////////// 38 | //////////////////////..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.///////////////////// 39 | /////////////////////////..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.//////////////////////// 40 | /////////////////////////////..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@../////////////////////////// 41 | /////////////////////////////////..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@../////////////////////////////// 42 | //////////////////////////////////////...@@@@@@@@@@@@@@@@@@@@@@@@@@@@...//////////////////////////////////// 43 | //////////////////////////////////////////////...@@@@@@@@@@@@@@...////////////////////////////////////////// 44 | //////////////////////////////////////////////////.@@@@@@@@@//////////////////////////////////////////////// 45 | ////////////////////////////////////////////////.@@@@@./@@@@@/////////////////////////////////////////////// 46 | ///////////////////////////////////////////////.@@@@@@///@@@@@.///////////////////////////////////////////// 47 | /////////////////////////////////////////////.@@@@@@@/.@./@@@@@@./////////////////////////////////////////// 48 | ////////////////////////////////////////////@@@@@@@@/.@@@/.@@@@@@@.///////////////////////////////////////// 49 | ///////////////////////////////////////////.@@@@@@@//@@@@@//@@@@@@@.//////////////////////////////////////// 50 | ////////////////////////////////////////////.@@@@@./@@@@@@@/.@@@@@.///////////////////////////////////////// 51 | //////////////////////////////////////////////.@@./@@@@@@@@@/.@@./////////////////////////////////////////// 52 | ///////////////////////////////////////////////../@@@@@@@@@@@/..//////////////////////////////////////////// 53 | /////////////////////////////////////////////////@@@@@@@@@@@@@////////////////////////////////////////////// 54 | ////////////////////////////////////////////////@@@@@@@@@@@@@@@///////////////////////////////////////////// 55 | ///////////////////////////////////////////////@@@@@@.///.@@@@@.//////////////////////////////////////////// 56 | //////////////////////////////////////////////.@@..//.@@..//..@@./////////////////////////////////////////// 57 | /////////////////////////////////////////////..//////@@@@//////...////////////////////////////////////////// 58 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 60 | /////////////_______///________//____////____//_______//______///////__///__////______////______//////////// 61 | /////////////@@_____|//@@@__@@@\/\@@@\ /@@@//|@@@____||@@@_ \/////|@@\ |@@|/// __ \//|@@@_@@\/////////// 62 | ////////////|@@|//__//|@@| |@@|//\@@@\/@@@///|@@|__///|@@|_) |////|@@@\|@@|/|@@| |@@|/|@@|_)@@|////////// 63 | ////////////|@@| |_@|/|@@| |@@|///\@@@@@@////|@@@__|//|@@@@@@//////|@@.@`@@|/|@@| |@@|/|@@@@@@//////////// 64 | ////////////|@@|__|@|/|@@`--'@@|////\@@@@/////|@@|____/|@@|\@@\----.|@@|\@@@|/|@@`--'@@|/|@@|\@@\----.////// 65 | /////////////\______|//\______///////\__//////|_______|| _| `._____||__| \__|//\______///|@_| `._____|////// 66 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 67 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 68 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 69 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 70 | 71 | // SPDX-License-Identifier: UNLICENSED 72 | pragma solidity ^0.6.0; 73 | 74 | abstract contract IERC20 { 75 | function totalSupply() external virtual view returns (uint256); 76 | function balanceOf(address tokenOwner) external virtual view returns (uint256 balance); 77 | function allowance(address tokenOwner, address spender) external virtual view returns (uint256 remaining); 78 | function transfer(address to, uint256 tokens) external virtual returns (bool success); 79 | function approve(address spender, uint256 tokens) external virtual returns (bool success); 80 | function transferFrom(address from, address to, uint256 tokens) external virtual returns (bool success); 81 | function burnFrom(address account, uint256 amount) public virtual; 82 | 83 | event Transfer(address indexed from, address indexed to, uint256 tokens); 84 | event Approval(address indexed tokenOwner, address indexed spender, uint256 tokens); 85 | } 86 | 87 | contract Swapico { 88 | 89 | address public immutable synthetico; 90 | address public immutable authentico; 91 | uint256 public immutable inicio; 92 | 93 | event purchased(address indexed _purchaser, uint256 indexed _tokens); 94 | 95 | constructor(address _synthetico, address _authentico, uint256 _inicio) public { 96 | synthetico = _synthetico; 97 | authentico = _authentico; 98 | inicio = _inicio; 99 | } 100 | 101 | function purchase(uint256 amount) public { 102 | require(block.timestamp >= inicio, 'purchase: too soon'); 103 | require(IERC20(synthetico).balanceOf(address(msg.sender)) >= amount, 'purchase: insufficient balance'); 104 | require(IERC20(authentico).balanceOf(address(this)) >= amount, 'purchase: insufficient liquidity'); 105 | _purchase(amount); 106 | } 107 | 108 | function _purchase(uint256 _amount) internal { 109 | IERC20(synthetico).burnFrom(msg.sender, _amount); 110 | IERC20(authentico).transfer(msg.sender, _amount); 111 | 112 | emit purchased(msg.sender, _amount); 113 | } 114 | } -------------------------------------------------------------------------------- /liquidity-mine/contracts/GovTreasurer.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.12; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; 6 | import "@openzeppelin/contracts/utils/EnumerableSet.sol"; 7 | import "@openzeppelin/contracts/math/SafeMath.sol"; 8 | import "@openzeppelin/contracts/access/Ownable.sol"; 9 | 10 | // 11 | // GovTreasurer is the treasurer of GDAO. She may allocate GDAO and she is a fair lady <3 12 | // Note that it's ownable and the owner wields tremendous power. The ownership 13 | // will be transferred to a governance smart contract once GDAO is sufficiently 14 | // distributed and the community can show to govern itself. 15 | contract GovTreasurer is Ownable { 16 | using SafeMath for uint256; 17 | using SafeERC20 for IERC20; 18 | address devaddr; 19 | address public treasury; 20 | IERC20 public gdao; 21 | uint256 public bonusEndBlock; 22 | uint256 public GDAOPerBlock; 23 | 24 | 25 | // INFO | USER VARIABLES 26 | struct UserInfo { 27 | uint256 amount; // How many tokens the user has provided. 28 | uint256 rewardDebt; // Reward debt. See explanation below. 29 | // 30 | // The pending GDAO entitled to a user is referred to as the pending reward: 31 | // 32 | // pending reward = (user.amount * pool.accGDAOPerShare) - user.rewardDebt - user.taxedAmount 33 | // 34 | // Upon deposit and withdraw, the following occur: 35 | // 1. The pool's `accGDAOPerShare` (and `lastRewardBlock`) gets updated. 36 | // 2. User receives the pending reward sent to his/her address. 37 | // 3. User's `amount` gets updated and taxed as 'taxedAmount'. 38 | // 4. User's `rewardDebt` gets updated. 39 | } 40 | 41 | // INFO | POOL VARIABLES 42 | struct PoolInfo { 43 | IERC20 token; // Address of token contract. 44 | uint256 allocPoint; // How many allocation points assigned to this pool. GDAOs to distribute per block. 45 | uint256 taxRate; // Rate at which the LP token is taxed. 46 | uint256 lastRewardBlock; // Last block number that GDAOs distribution occurs. 47 | uint256 accGDAOPerShare; // Accumulated GDAOs per share, times 1e12. See below. 48 | } 49 | 50 | PoolInfo[] public poolInfo; 51 | mapping (uint256 => mapping (address => UserInfo)) public userInfo; 52 | uint256 public totalAllocPoint = 0; 53 | uint256 public startBlock; 54 | 55 | event Deposit(address indexed user, uint256 indexed pid, uint256 amount); 56 | event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); 57 | event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); 58 | 59 | constructor(IERC20 _gdao, address _treasury, uint256 _GDAOPerBlock, uint256 _startBlock, uint256 _bonusEndBlock) public { 60 | gdao = _gdao; 61 | treasury = _treasury; 62 | devaddr = msg.sender; 63 | GDAOPerBlock = _GDAOPerBlock; 64 | startBlock = _startBlock; 65 | bonusEndBlock = _bonusEndBlock; 66 | } 67 | 68 | function poolLength() external view returns (uint256) { 69 | return poolInfo.length; 70 | } 71 | 72 | 73 | // VALIDATION | ELIMINATES POOL DUPLICATION RISK 74 | function checkPoolDuplicate(IERC20 _token) public view { 75 | uint256 length = poolInfo.length; 76 | for (uint256 pid = 0; pid < length; ++pid) { 77 | require(poolInfo[pid].token != _token, "add: existing pool?"); 78 | } 79 | } 80 | 81 | // ADD | NEW TOKEN POOL 82 | function add(uint256 _allocPoint, IERC20 _token, uint256 _taxRate, bool _withUpdate) public 83 | onlyOwner { 84 | if (_withUpdate) { 85 | massUpdatePools(); 86 | } 87 | uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; 88 | totalAllocPoint = totalAllocPoint.add(_allocPoint); 89 | poolInfo.push(PoolInfo({ 90 | token: _token, 91 | allocPoint: _allocPoint, 92 | taxRate: _taxRate, 93 | lastRewardBlock: lastRewardBlock, 94 | accGDAOPerShare: 0 95 | })); 96 | } 97 | 98 | // UPDATE | ALLOCATION POINT 99 | function set(uint256 _pid, uint256 _allocPoint, bool _withUpdate) public onlyOwner { 100 | if (_withUpdate) { 101 | massUpdatePools(); 102 | } 103 | totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint); 104 | poolInfo[_pid].allocPoint = _allocPoint; 105 | } 106 | 107 | // RETURN | REWARD MULTIPLIER OVER GIVEN BLOCK RANGE | INCLUDES START BLOCK 108 | function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) { 109 | _from = _from >= startBlock ? _from : startBlock; 110 | if (_to <= bonusEndBlock) { 111 | return _to.sub(_from); 112 | } else if (_from >= bonusEndBlock) { 113 | return _to.sub(_from); 114 | } else { 115 | return bonusEndBlock.sub(_from).add( 116 | _to.sub(bonusEndBlock) 117 | ); 118 | } 119 | } 120 | 121 | // VIEW | PENDING REWARD 122 | function pendingGDAO(uint256 _pid, address _user) external view returns (uint256) { 123 | PoolInfo storage pool = poolInfo[_pid]; 124 | UserInfo storage user = userInfo[_pid][_user]; 125 | uint256 accGDAOPerShare = pool.accGDAOPerShare; 126 | uint256 lpSupply = pool.token.balanceOf(address(this)); 127 | if (block.number > pool.lastRewardBlock && lpSupply != 0) { 128 | uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); 129 | uint256 GDAOReward = multiplier.mul(GDAOPerBlock).mul(pool.allocPoint).div(totalAllocPoint); 130 | accGDAOPerShare = accGDAOPerShare.add(GDAOReward.mul(1e12).div(lpSupply)); 131 | } 132 | return user.amount.mul(accGDAOPerShare).div(1e12).sub(user.rewardDebt); 133 | } 134 | 135 | // UPDATE | (ALL) REWARD VARIABLES | BEWARE: HIGH GAS POTENTIAL 136 | function massUpdatePools() public { 137 | uint256 length = poolInfo.length; 138 | for (uint256 pid = 0; pid < length; ++pid) { 139 | updatePool(pid); 140 | } 141 | } 142 | 143 | // UPDATE | (ONE POOL) REWARD VARIABLES 144 | function updatePool(uint256 _pid) public { 145 | PoolInfo storage pool = poolInfo[_pid]; 146 | if (block.number <= pool.lastRewardBlock) { 147 | return; 148 | } 149 | uint256 lpSupply = pool.token.balanceOf(address(this)); 150 | if (lpSupply == 0) { 151 | pool.lastRewardBlock = block.number; 152 | return; 153 | } 154 | uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); 155 | uint256 GDAOReward = multiplier.mul(GDAOPerBlock).mul(pool.allocPoint).div(totalAllocPoint); 156 | safeGDAOTransfer(address(this), GDAOReward); 157 | pool.accGDAOPerShare = pool.accGDAOPerShare.add(GDAOReward.mul(1e12).div(lpSupply)); 158 | pool.lastRewardBlock = block.number; 159 | } 160 | 161 | // VALIDATE | AUTHENTICATE _PID 162 | modifier validatePool(uint256 _pid) { 163 | require(_pid < poolInfo.length, "gov: pool exists?"); 164 | _; 165 | } 166 | 167 | // WITHDRAW | ASSETS (TOKENS) WITH NO REWARDS | EMERGENCY ONLY 168 | function emergencyWithdraw(uint256 _pid) public { 169 | PoolInfo storage pool = poolInfo[_pid]; 170 | UserInfo storage user = userInfo[_pid][msg.sender]; 171 | 172 | user.amount = 0; 173 | user.rewardDebt = 0; 174 | 175 | pool.token.safeTransfer(address(msg.sender), user.amount); 176 | 177 | emit EmergencyWithdraw(msg.sender, _pid, user.amount); 178 | } 179 | 180 | // DEPOSIT | ASSETS (TOKENS) 181 | function deposit(uint256 _pid, uint256 _amount) public { 182 | PoolInfo storage pool = poolInfo[_pid]; 183 | UserInfo storage user = userInfo[_pid][msg.sender]; 184 | updatePool(_pid); 185 | uint256 taxedAmount = _amount.div(pool.taxRate); 186 | 187 | if (user.amount > 0) { // if there are already some amount deposited 188 | uint256 pending = user.amount.mul(pool.accGDAOPerShare).div(1e12).sub(user.rewardDebt); 189 | if(pending > 0) { // sends pending rewards, if applicable 190 | safeGDAOTransfer(msg.sender, pending); 191 | } 192 | } 193 | 194 | if(_amount > 0) { // if adding more 195 | pool.token.safeTransferFrom(address(msg.sender), address(this), _amount.sub(taxedAmount)); 196 | pool.token.safeTransferFrom(address(msg.sender), address(treasury), taxedAmount); 197 | user.amount = user.amount.add(_amount.sub(taxedAmount)); // update user.amount = non-taxed amount 198 | } 199 | 200 | user.rewardDebt = user.amount.mul(pool.accGDAOPerShare).div(1e12); 201 | emit Deposit(msg.sender, _pid, _amount.sub(taxedAmount)); 202 | } 203 | 204 | // WITHDRAW | ASSETS (TOKENS) 205 | function withdraw(uint256 _pid, uint256 _amount) public { 206 | PoolInfo storage pool = poolInfo[_pid]; 207 | UserInfo storage user = userInfo[_pid][msg.sender]; 208 | require(user.amount >= _amount, "withdraw: not good"); 209 | updatePool(_pid); 210 | uint256 pending = user.amount.mul(pool.accGDAOPerShare).div(1e12).sub(user.rewardDebt); 211 | 212 | if(pending > 0) { // send pending GDAO rewards 213 | safeGDAOTransfer(msg.sender, pending); 214 | } 215 | 216 | if(_amount > 0) { 217 | user.amount = user.amount.sub(_amount); 218 | pool.token.safeTransfer(address(msg.sender), _amount); 219 | } 220 | 221 | user.rewardDebt = user.amount.mul(pool.accGDAOPerShare).div(1e12); 222 | emit Withdraw(msg.sender, _pid, _amount); 223 | } 224 | 225 | // SAFE TRANSFER FUNCTION | ACCOUNTS FOR ROUNDING ERRORS | ENSURES SUFFICIENT GDAO IN POOLS. 226 | function safeGDAOTransfer(address _to, uint256 _amount) internal { 227 | uint256 GDAOBal = gdao.balanceOf(address(this)); 228 | if (_amount > GDAOBal) { 229 | gdao.transfer(_to, GDAOBal); 230 | } else { 231 | gdao.transfer(_to, _amount); 232 | } 233 | } 234 | 235 | // UPDATE | DEV ADDRESS | DEV-ONLY 236 | function dev(address _devaddr) public { 237 | require(msg.sender == devaddr, "dev: wut?"); 238 | devaddr = _devaddr; 239 | } 240 | } 241 | -------------------------------------------------------------------------------- /merkle-distributor/test/MerkleDistributor.spec.ts: -------------------------------------------------------------------------------- 1 | import chai, { expect } from 'chai' 2 | import { solidity, MockProvider, deployContract } from 'ethereum-waffle' 3 | import { Contract, BigNumber, constants } from 'ethers' 4 | import BalanceTree from '../src/balance-tree' 5 | 6 | import Distributor from '../build/MerkleDistributor.json' 7 | import TestERC20 from '../build/TestERC20.json' 8 | import { parseBalanceMap } from '../src/parse-balance-map' 9 | 10 | chai.use(solidity) 11 | 12 | const overrides = { 13 | gasLimit: 9999999, 14 | } 15 | 16 | const ZERO_BYTES32 = '0x0000000000000000000000000000000000000000000000000000000000000000' 17 | const StartTime = 1607495500; 18 | const EndTime = 1616630400; 19 | 20 | describe('MerkleDistributor', () => { 21 | const provider = new MockProvider({ 22 | ganacheOptions: { 23 | hardfork: 'istanbul', 24 | mnemonic: 'horn horn horn horn horn horn horn horn horn horn horn horn', 25 | gasLimit: 9999999, 26 | }, 27 | }) 28 | 29 | const wallets = provider.getWallets() 30 | const [wallet0, wallet1] = wallets 31 | 32 | let token: Contract 33 | beforeEach('deploy token', async () => { 34 | token = await deployContract(wallet0, TestERC20, ['Token', 'TKN', 0], overrides) 35 | }) 36 | 37 | describe('#token', () => { 38 | it('returns the token address', async () => { 39 | const distributor = await deployContract(wallet0, Distributor, [token.address, ZERO_BYTES32, StartTime, EndTime], overrides) 40 | expect(await distributor.token()).to.eq(token.address) 41 | }) 42 | }) 43 | 44 | describe('#merkleRoot', () => { 45 | it('returns the zero merkle root', async () => { 46 | const distributor = await deployContract(wallet0, Distributor, [token.address, ZERO_BYTES32, StartTime, EndTime], overrides) 47 | expect(await distributor.merkleRoot()).to.eq(ZERO_BYTES32) 48 | }) 49 | }) 50 | 51 | describe('#claim', () => { 52 | it('fails for empty proof', async () => { 53 | const distributor = await deployContract(wallet0, Distributor, [token.address, ZERO_BYTES32, StartTime, EndTime], overrides) 54 | await expect(distributor.claim(0, wallet0.address, 10, [])).to.be.revertedWith( 55 | 'MerkleDistributor: Invalid proof.' 56 | ) 57 | }) 58 | 59 | it('fails for invalid index', async () => { 60 | const distributor = await deployContract(wallet0, Distributor, [token.address, ZERO_BYTES32, StartTime, EndTime], overrides) 61 | await expect(distributor.claim(0, wallet0.address, 10, [])).to.be.revertedWith( 62 | 'MerkleDistributor: Invalid proof.' 63 | ) 64 | }) 65 | 66 | describe('two account tree', () => { 67 | let distributor: Contract 68 | let tree: BalanceTree 69 | beforeEach('deploy', async () => { 70 | tree = new BalanceTree([ 71 | { account: wallet0.address, amount: BigNumber.from(100) }, 72 | { account: wallet1.address, amount: BigNumber.from(101) }, 73 | ]) 74 | distributor = await deployContract(wallet0, Distributor, [token.address, tree.getHexRoot(), StartTime, EndTime], overrides) 75 | await token.setBalance(distributor.address, 201) 76 | }) 77 | 78 | it('successful claim', async () => { 79 | const proof0 = tree.getProof(0, wallet0.address, BigNumber.from(100)) 80 | await expect(distributor.claim(0, wallet0.address, 100, proof0, overrides)) 81 | .to.emit(distributor, 'Claimed') 82 | .withArgs(0, wallet0.address, 100) 83 | const proof1 = tree.getProof(1, wallet1.address, BigNumber.from(101)) 84 | await expect(distributor.claim(1, wallet1.address, 101, proof1, overrides)) 85 | .to.emit(distributor, 'Claimed') 86 | .withArgs(1, wallet1.address, 101) 87 | }) 88 | 89 | it('transfers the token', async () => { 90 | const proof0 = tree.getProof(0, wallet0.address, BigNumber.from(100)) 91 | expect(await token.balanceOf(wallet0.address)).to.eq(0) 92 | await distributor.claim(0, wallet0.address, 100, proof0, overrides) 93 | expect(await token.balanceOf(wallet0.address)).to.eq(100) 94 | }) 95 | 96 | it('must have enough to transfer', async () => { 97 | const proof0 = tree.getProof(0, wallet0.address, BigNumber.from(100)) 98 | await token.setBalance(distributor.address, 99) 99 | await expect(distributor.claim(0, wallet0.address, 100, proof0, overrides)).to.be.revertedWith( 100 | 'ERC20: transfer amount exceeds balance' 101 | ) 102 | }) 103 | 104 | it('sets #isClaimed', async () => { 105 | const proof0 = tree.getProof(0, wallet0.address, BigNumber.from(100)) 106 | expect(await distributor.isClaimed(0)).to.eq(false) 107 | expect(await distributor.isClaimed(1)).to.eq(false) 108 | await distributor.claim(0, wallet0.address, 100, proof0, overrides) 109 | expect(await distributor.isClaimed(0)).to.eq(true) 110 | expect(await distributor.isClaimed(1)).to.eq(false) 111 | }) 112 | 113 | it('cannot allow two claims', async () => { 114 | const proof0 = tree.getProof(0, wallet0.address, BigNumber.from(100)) 115 | await distributor.claim(0, wallet0.address, 100, proof0, overrides) 116 | await expect(distributor.claim(0, wallet0.address, 100, proof0, overrides)).to.be.revertedWith( 117 | 'MerkleDistributor: Drop already claimed.' 118 | ) 119 | }) 120 | 121 | it('cannot claim more than once: 0 and then 1', async () => { 122 | await distributor.claim( 123 | 0, 124 | wallet0.address, 125 | 100, 126 | tree.getProof(0, wallet0.address, BigNumber.from(100)), 127 | overrides 128 | ) 129 | await distributor.claim( 130 | 1, 131 | wallet1.address, 132 | 101, 133 | tree.getProof(1, wallet1.address, BigNumber.from(101)), 134 | overrides 135 | ) 136 | 137 | await expect( 138 | distributor.claim(0, wallet0.address, 100, tree.getProof(0, wallet0.address, BigNumber.from(100)), overrides) 139 | ).to.be.revertedWith('MerkleDistributor: Drop already claimed.') 140 | }) 141 | 142 | it('cannot claim more than once: 1 and then 0', async () => { 143 | await distributor.claim( 144 | 1, 145 | wallet1.address, 146 | 101, 147 | tree.getProof(1, wallet1.address, BigNumber.from(101)), 148 | overrides 149 | ) 150 | await distributor.claim( 151 | 0, 152 | wallet0.address, 153 | 100, 154 | tree.getProof(0, wallet0.address, BigNumber.from(100)), 155 | overrides 156 | ) 157 | 158 | await expect( 159 | distributor.claim(1, wallet1.address, 101, tree.getProof(1, wallet1.address, BigNumber.from(101)), overrides) 160 | ).to.be.revertedWith('MerkleDistributor: Drop already claimed.') 161 | }) 162 | 163 | it('cannot claim for address other than proof', async () => { 164 | const proof0 = tree.getProof(0, wallet0.address, BigNumber.from(100)) 165 | await expect(distributor.claim(1, wallet1.address, 101, proof0, overrides)).to.be.revertedWith( 166 | 'MerkleDistributor: Invalid proof.' 167 | ) 168 | }) 169 | 170 | it('cannot claim more than proof', async () => { 171 | const proof0 = tree.getProof(0, wallet0.address, BigNumber.from(100)) 172 | await expect(distributor.claim(0, wallet0.address, 101, proof0, overrides)).to.be.revertedWith( 173 | 'MerkleDistributor: Invalid proof.' 174 | ) 175 | }) 176 | }) 177 | describe('larger tree', () => { 178 | let distributor: Contract 179 | let tree: BalanceTree 180 | beforeEach('deploy', async () => { 181 | tree = new BalanceTree( 182 | wallets.map((wallet, ix) => { 183 | return { account: wallet.address, amount: BigNumber.from(ix + 1) } 184 | }) 185 | ) 186 | distributor = await deployContract(wallet0, Distributor, [token.address, tree.getHexRoot(), StartTime, EndTime], overrides) 187 | await token.setBalance(distributor.address, 201) 188 | }) 189 | 190 | it('claim index 4', async () => { 191 | const proof = tree.getProof(4, wallets[4].address, BigNumber.from(5)) 192 | await expect(distributor.claim(4, wallets[4].address, 5, proof, overrides)) 193 | .to.emit(distributor, 'Claimed') 194 | .withArgs(4, wallets[4].address, 5) 195 | }) 196 | 197 | it('claim index 9', async () => { 198 | const proof = tree.getProof(9, wallets[9].address, BigNumber.from(10)) 199 | await expect(distributor.claim(9, wallets[9].address, 10, proof, overrides)) 200 | .to.emit(distributor, 'Claimed') 201 | .withArgs(9, wallets[9].address, 10) 202 | }) 203 | }) 204 | 205 | describe('realistic size tree', () => { 206 | let distributor: Contract 207 | let tree: BalanceTree 208 | const NUM_LEAVES = 100_000 209 | const NUM_SAMPLES = 25 210 | const elements: { account: string; amount: BigNumber }[] = [] 211 | for (let i = 0; i < NUM_LEAVES; i++) { 212 | const node = { account: wallet0.address, amount: BigNumber.from(100) } 213 | elements.push(node) 214 | } 215 | tree = new BalanceTree(elements) 216 | 217 | it('proof verification works', () => { 218 | const root = Buffer.from(tree.getHexRoot().slice(2), 'hex') 219 | for (let i = 0; i < NUM_LEAVES; i += NUM_LEAVES / NUM_SAMPLES) { 220 | const proof = tree 221 | .getProof(i, wallet0.address, BigNumber.from(100)) 222 | .map((el) => Buffer.from(el.slice(2), 'hex')) 223 | const validProof = BalanceTree.verifyProof(i, wallet0.address, BigNumber.from(100), proof, root) 224 | expect(validProof).to.be.true 225 | } 226 | }) 227 | 228 | beforeEach('deploy', async () => { 229 | distributor = await deployContract(wallet0, Distributor, [token.address, tree.getHexRoot(), StartTime, EndTime], overrides) 230 | await token.setBalance(distributor.address, constants.MaxUint256) 231 | }) 232 | it('no double claims in random distribution', async () => { 233 | for (let i = 0; i < 25; i += Math.floor(Math.random() * (NUM_LEAVES / NUM_SAMPLES))) { 234 | const proof = tree.getProof(i, wallet0.address, BigNumber.from(100)) 235 | await distributor.claim(i, wallet0.address, 100, proof, overrides) 236 | await expect(distributor.claim(i, wallet0.address, 100, proof, overrides)).to.be.revertedWith( 237 | 'MerkleDistributor: Drop already claimed.' 238 | ) 239 | } 240 | }) 241 | }) 242 | }) 243 | 244 | describe('parseBalanceMap', () => { 245 | let distributor: Contract 246 | let claims: { 247 | [account: string]: { 248 | index: number 249 | amount: string 250 | proof: string[] 251 | } 252 | } 253 | beforeEach('deploy', async () => { 254 | const { claims: innerClaims, merkleRoot, tokenTotal } = parseBalanceMap({ 255 | [wallet0.address]: 200, 256 | [wallet1.address]: 300, 257 | [wallets[2].address]: 250, 258 | }) 259 | expect(tokenTotal).to.eq('0x02ee') // 750 260 | claims = innerClaims 261 | distributor = await deployContract(wallet0, Distributor, [token.address, merkleRoot, StartTime, EndTime], overrides) 262 | await token.setBalance(distributor.address, tokenTotal) 263 | }) 264 | 265 | it('check the proofs is as expected', () => { 266 | expect(claims).to.deep.eq({ 267 | [wallet0.address]: { 268 | index: 0, 269 | amount: '0xc8', 270 | proof: ['0x2a411ed78501edb696adca9e41e78d8256b61cfac45612fa0434d7cf87d916c6'], 271 | }, 272 | [wallet1.address]: { 273 | index: 1, 274 | amount: '0x012c', 275 | proof: [ 276 | '0xbfeb956a3b705056020a3b64c540bff700c0f6c96c55c0a5fcab57124cb36f7b', 277 | '0xd31de46890d4a77baeebddbd77bf73b5c626397b73ee8c69b51efe4c9a5a72fa', 278 | ], 279 | }, 280 | [wallets[2].address]: { 281 | index: 2, 282 | amount: '0xfa', 283 | proof: [ 284 | '0xceaacce7533111e902cc548e961d77b23a4d8cd073c6b68ccf55c62bd47fc36b', 285 | '0xd31de46890d4a77baeebddbd77bf73b5c626397b73ee8c69b51efe4c9a5a72fa', 286 | ], 287 | }, 288 | }) 289 | }) 290 | it('all claims work exactly once', async () => { 291 | for (let account in claims) { 292 | const claim = claims[account] 293 | await expect(distributor.claim(claim.index, account, claim.amount, claim.proof, overrides)) 294 | .to.emit(distributor, 'Claimed') 295 | .withArgs(claim.index, account, claim.amount) 296 | await expect(distributor.claim(claim.index, account, claim.amount, claim.proof, overrides)).to.be.revertedWith( 297 | 'MerkleDistributor: Drop already claimed.' 298 | ) 299 | } 300 | expect(await token.balanceOf(distributor.address)).to.eq(0) 301 | }) 302 | }) 303 | }) 304 | -------------------------------------------------------------------------------- /merkle-distributor/contracts/MerkleDistributor_flat.sol: -------------------------------------------------------------------------------- 1 | 2 | // SPDX-License-Identifier: MIT 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 | * @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 `recipient`. 22 | * 23 | * Returns a boolean value indicating whether the operation succeeded. 24 | * 25 | * Emits a {Transfer} event. 26 | */ 27 | function transfer(address recipient, 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 `sender` to `recipient` 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(address sender, address recipient, uint256 amount) external returns (bool); 64 | 65 | /** 66 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 67 | * another (`to`). 68 | * 69 | * Note that `value` may be zero. 70 | */ 71 | event Transfer(address indexed from, address indexed to, uint256 value); 72 | 73 | /** 74 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 75 | * a call to {approve}. `value` is the new allowance. 76 | */ 77 | event Approval(address indexed owner, address indexed spender, uint256 value); 78 | } 79 | 80 | 81 | pragma solidity ^0.6.0; 82 | 83 | /** 84 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 85 | * checks. 86 | * 87 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 88 | * in bugs, because programmers usually assume that an overflow raises an 89 | * error, which is the standard behavior in high level programming languages. 90 | * `SafeMath` restores this intuition by reverting the transaction when an 91 | * operation overflows. 92 | * 93 | * Using this library instead of the unchecked operations eliminates an entire 94 | * class of bugs, so it's recommended to use it always. 95 | */ 96 | library SafeMath { 97 | /** 98 | * @dev Returns the addition of two unsigned integers, reverting on 99 | * overflow. 100 | * 101 | * Counterpart to Solidity's `+` operator. 102 | * 103 | * Requirements: 104 | * 105 | * - Addition cannot overflow. 106 | */ 107 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 108 | uint256 c = a + b; 109 | require(c >= a, "SafeMath: addition overflow"); 110 | 111 | return c; 112 | } 113 | 114 | /** 115 | * @dev Returns the subtraction of two unsigned integers, reverting on 116 | * overflow (when the result is negative). 117 | * 118 | * Counterpart to Solidity's `-` operator. 119 | * 120 | * Requirements: 121 | * 122 | * - Subtraction cannot overflow. 123 | */ 124 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 125 | return sub(a, b, "SafeMath: subtraction overflow"); 126 | } 127 | 128 | /** 129 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 130 | * overflow (when the result is negative). 131 | * 132 | * Counterpart to Solidity's `-` operator. 133 | * 134 | * Requirements: 135 | * 136 | * - Subtraction cannot overflow. 137 | */ 138 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 139 | require(b <= a, errorMessage); 140 | uint256 c = a - b; 141 | 142 | return c; 143 | } 144 | 145 | /** 146 | * @dev Returns the multiplication of two unsigned integers, reverting on 147 | * overflow. 148 | * 149 | * Counterpart to Solidity's `*` operator. 150 | * 151 | * Requirements: 152 | * 153 | * - Multiplication cannot overflow. 154 | */ 155 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 156 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 157 | // benefit is lost if 'b' is also tested. 158 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 159 | if (a == 0) { 160 | return 0; 161 | } 162 | 163 | uint256 c = a * b; 164 | require(c / a == b, "SafeMath: multiplication overflow"); 165 | 166 | return c; 167 | } 168 | 169 | /** 170 | * @dev Returns the integer division of two unsigned integers. Reverts on 171 | * division by zero. The result is rounded towards zero. 172 | * 173 | * Counterpart to Solidity's `/` operator. Note: this function uses a 174 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 175 | * uses an invalid opcode to revert (consuming all remaining gas). 176 | * 177 | * Requirements: 178 | * 179 | * - The divisor cannot be zero. 180 | */ 181 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 182 | return div(a, b, "SafeMath: division by zero"); 183 | } 184 | 185 | /** 186 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 187 | * division by zero. The result is rounded towards zero. 188 | * 189 | * Counterpart to Solidity's `/` operator. Note: this function uses a 190 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 191 | * uses an invalid opcode to revert (consuming all remaining gas). 192 | * 193 | * Requirements: 194 | * 195 | * - The divisor cannot be zero. 196 | */ 197 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 198 | require(b > 0, errorMessage); 199 | uint256 c = a / b; 200 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 201 | 202 | return c; 203 | } 204 | 205 | /** 206 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 207 | * Reverts when dividing by zero. 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(uint256 a, uint256 b) internal pure returns (uint256) { 218 | return mod(a, b, "SafeMath: modulo by zero"); 219 | } 220 | 221 | /** 222 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 223 | * Reverts with custom message when dividing by zero. 224 | * 225 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 226 | * opcode (which leaves remaining gas untouched) while Solidity uses an 227 | * invalid opcode to revert (consuming all remaining gas). 228 | * 229 | * Requirements: 230 | * 231 | * - The divisor cannot be zero. 232 | */ 233 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 234 | require(b != 0, errorMessage); 235 | return a % b; 236 | } 237 | } 238 | 239 | 240 | pragma solidity ^0.6.0; 241 | 242 | /** 243 | * @dev These functions deal with verification of Merkle trees (hash trees), 244 | */ 245 | library MerkleProof { 246 | /** 247 | * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree 248 | * defined by `root`. For this, a `proof` must be provided, containing 249 | * sibling hashes on the branch from the leaf to the root of the tree. Each 250 | * pair of leaves and each pair of pre-images are assumed to be sorted. 251 | */ 252 | function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) { 253 | bytes32 computedHash = leaf; 254 | 255 | for (uint256 i = 0; i < proof.length; i++) { 256 | bytes32 proofElement = proof[i]; 257 | 258 | if (computedHash <= proofElement) { 259 | // Hash(current computed hash + current element of the proof) 260 | computedHash = keccak256(abi.encodePacked(computedHash, proofElement)); 261 | } else { 262 | // Hash(current element of the proof + current computed hash) 263 | computedHash = keccak256(abi.encodePacked(proofElement, computedHash)); 264 | } 265 | } 266 | 267 | // Check if the computed hash (root) is equal to the provided root 268 | return computedHash == root; 269 | } 270 | } 271 | 272 | pragma solidity >=0.5.0; 273 | 274 | // Allows anyone to claim a token if they exist in a merkle root. 275 | interface IMerkleDistributor { 276 | // Returns the address of the token distributed by this contract. 277 | function token() external view returns (address); 278 | // Returns the merkle root of the merkle tree containing account balances available to claim. 279 | function merkleRoot() external view returns (bytes32); 280 | // Returns the address of the rewards pool contributed to by this contract. 281 | function rewardsAddress() external view returns (address); 282 | // Returns the address of the burn pool contributed to by this contract. 283 | function burnAddress() external view returns (address); 284 | // Returns true if the index has been marked claimed. 285 | function isClaimed(uint256 index) external view returns (bool); 286 | 287 | // Claim the given amount of the token to the given address. Reverts if the inputs are invalid. 288 | function claim(uint256 index, address account, uint256 amount, bytes32[] calldata merkleProof) external; 289 | // This event is triggered whenever a call to #claim succeeds. 290 | event Claimed(uint256 index, address account, uint256 amount); 291 | } 292 | 293 | 294 | pragma solidity =0.6.11; 295 | 296 | contract MerkleDistributor is IMerkleDistributor { 297 | using SafeMath for uint256; 298 | address public immutable override token; 299 | bytes32 public immutable override merkleRoot; 300 | address public immutable override rewardsAddress; 301 | address public immutable override burnAddress; 302 | 303 | mapping(uint256 => uint256) private claimedBitMap; 304 | address deployer; 305 | 306 | uint256 public immutable startTime; 307 | uint256 public immutable endTime; 308 | uint256 internal immutable secondsInaDay = 86400; 309 | 310 | constructor(address token_, bytes32 merkleRoot_, address rewardsAddress_, address burnAddress_, uint256 startTime_, uint256 endTime_) public { 311 | token = token_; 312 | merkleRoot = merkleRoot_; 313 | rewardsAddress = rewardsAddress_; 314 | burnAddress = burnAddress_; 315 | deployer = msg.sender; 316 | startTime = startTime_; 317 | endTime = endTime_; 318 | } 319 | 320 | function isClaimed(uint256 index) public view override returns (bool) { 321 | uint256 claimedWordIndex = index / 256; 322 | uint256 claimedBitIndex = index % 256; 323 | uint256 claimedWord = claimedBitMap[claimedWordIndex]; 324 | uint256 mask = (1 << claimedBitIndex); 325 | return claimedWord & mask == mask; 326 | } 327 | 328 | function _setClaimed(uint256 index) private { 329 | uint256 claimedWordIndex = index / 256; 330 | uint256 claimedBitIndex = index % 256; 331 | claimedBitMap[claimedWordIndex] = claimedBitMap[claimedWordIndex] | (1 << claimedBitIndex); 332 | } 333 | 334 | function claim(uint256 index, address account, uint256 amount, bytes32[] calldata merkleProof) external override { 335 | require(msg.sender == account, 'MerkleDistributor: Only account may withdraw'); // ensures only account may withdraw on behalf of account 336 | require(!isClaimed(index), 'MerkleDistributor: Drop already claimed.'); 337 | 338 | bytes32 node = keccak256(abi.encodePacked(index, account, amount)); 339 | require(MerkleProof.verify(merkleProof, merkleRoot, node), 'MerkleDistributor: Invalid proof.'); 340 | 341 | // CLAIM AND SEND 342 | _setClaimed(index); 343 | uint256 duraTime = block.timestamp.sub(startTime); 344 | 345 | require(block.timestamp >= startTime, 'MerkleDistributor: Too soon'); 346 | require(block.timestamp <= endTime, 'MerkleDistributor: Too late'); 347 | 348 | uint256 duraDays = duraTime.div(secondsInaDay); 349 | require(duraDays <= 100, 'MerkleDistributor: Too late'); // limits available days 350 | 351 | uint256 claimableDays = duraDays >= 90 ? 90 : duraDays; // limits claimable days (90) 352 | uint256 claimableAmount = amount.mul(claimableDays.add(10)).div(100); // 10% + 1% daily 353 | require(claimableAmount <= amount, 'MerkleDistributor: Slow your roll'); // gem insurance 354 | uint256 forfeitedAmount = amount.sub(claimableAmount); 355 | 356 | require(IERC20(token).transfer(account, claimableAmount), 'MerkleDistributor: Transfer to Account failed.'); 357 | require(IERC20(token).transfer(rewardsAddress, forfeitedAmount.div(2)), 'MerkleDistributor: Transfer to rewardsAddress failed.'); 358 | require(IERC20(token).transfer(burnAddress, forfeitedAmount.div(2)), 'MerkleDistributor: Transfer to burnAddress failed.'); 359 | 360 | emit Claimed(index, account, amount); 361 | } 362 | 363 | function collectDust(address _token, uint256 _amount) external { 364 | require(msg.sender == deployer, '!deployer'); 365 | require(_token != token, '!token'); 366 | if (_token == address(0)) { // token address(0) = ETH 367 | payable(deployer).transfer(_amount); 368 | } else { 369 | IERC20(_token).transfer(deployer, _amount); 370 | } 371 | } 372 | 373 | function collectUnclaimed(uint256 amount) external{ 374 | require(msg.sender == deployer, 'MerkleDistributor: not deployer'); 375 | require(IERC20(token).transfer(deployer, amount), 'MerkleDistributor: collectUnclaimed failed.'); 376 | } 377 | 378 | function dev(address _deployer) public { 379 | require(msg.sender == deployer, "dev: wut?"); 380 | deployer = _deployer; 381 | } 382 | } 383 | -------------------------------------------------------------------------------- /gdao/flats/FlatGovernorToken.sol: -------------------------------------------------------------------------------- 1 | // File: @openzeppelin/contracts/GSN/Context.sol 2 | 3 | pragma solidity ^0.5.0; 4 | 5 | /* 6 | * @dev Provides information about the current execution context, including the 7 | * sender of the transaction and its data. While these are generally available 8 | * via msg.sender and msg.data, they should not be accessed in such a direct 9 | * manner, since when dealing with GSN meta-transactions the account sending and 10 | * paying for execution may not be the actual sender (as far as an application 11 | * is concerned). 12 | * 13 | * This contract is only required for intermediate, library-like contracts. 14 | */ 15 | contract Context { 16 | // Empty internal constructor, to prevent people from mistakenly deploying 17 | // an instance of this contract, which should be used via inheritance. 18 | constructor () internal { } 19 | // solhint-disable-previous-line no-empty-blocks 20 | 21 | function _msgSender() internal view returns (address payable) { 22 | return msg.sender; 23 | } 24 | 25 | function _msgData() internal view returns (bytes memory) { 26 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 27 | return msg.data; 28 | } 29 | } 30 | 31 | // File: @openzeppelin/contracts/token/ERC20/IERC20.sol 32 | 33 | pragma solidity ^0.5.0; 34 | 35 | /** 36 | * @dev Interface of the ERC20 standard as defined in the EIP. Does not include 37 | * the optional functions; to access them see {ERC20Detailed}. 38 | */ 39 | interface IERC20 { 40 | /** 41 | * @dev Returns the amount of tokens in existence. 42 | */ 43 | function totalSupply() external view returns (uint256); 44 | 45 | /** 46 | * @dev Returns the amount of tokens owned by `account`. 47 | */ 48 | function balanceOf(address account) external view returns (uint256); 49 | 50 | /** 51 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 52 | * 53 | * Returns a boolean value indicating whether the operation succeeded. 54 | * 55 | * Emits a {Transfer} event. 56 | */ 57 | function transfer(address recipient, uint256 amount) external returns (bool); 58 | 59 | /** 60 | * @dev Returns the remaining number of tokens that `spender` will be 61 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 62 | * zero by default. 63 | * 64 | * This value changes when {approve} or {transferFrom} are called. 65 | */ 66 | function allowance(address owner, address spender) external view returns (uint256); 67 | 68 | /** 69 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 70 | * 71 | * Returns a boolean value indicating whether the operation succeeded. 72 | * 73 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 74 | * that someone may use both the old and the new allowance by unfortunate 75 | * transaction ordering. One possible solution to mitigate this race 76 | * condition is to first reduce the spender's allowance to 0 and set the 77 | * desired value afterwards: 78 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 79 | * 80 | * Emits an {Approval} event. 81 | */ 82 | function approve(address spender, uint256 amount) external returns (bool); 83 | 84 | /** 85 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 86 | * allowance mechanism. `amount` is then deducted from the caller's 87 | * allowance. 88 | * 89 | * Returns a boolean value indicating whether the operation succeeded. 90 | * 91 | * Emits a {Transfer} event. 92 | */ 93 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 94 | 95 | /** 96 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 97 | * another (`to`). 98 | * 99 | * Note that `value` may be zero. 100 | */ 101 | event Transfer(address indexed from, address indexed to, uint256 value); 102 | 103 | /** 104 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 105 | * a call to {approve}. `value` is the new allowance. 106 | */ 107 | event Approval(address indexed owner, address indexed spender, uint256 value); 108 | } 109 | 110 | // File: @openzeppelin/contracts/math/SafeMath.sol 111 | 112 | pragma solidity ^0.5.0; 113 | 114 | /** 115 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 116 | * checks. 117 | * 118 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 119 | * in bugs, because programmers usually assume that an overflow raises an 120 | * error, which is the standard behavior in high level programming languages. 121 | * `SafeMath` restores this intuition by reverting the transaction when an 122 | * operation overflows. 123 | * 124 | * Using this library instead of the unchecked operations eliminates an entire 125 | * class of bugs, so it's recommended to use it always. 126 | */ 127 | library SafeMath { 128 | /** 129 | * @dev Returns the addition of two unsigned integers, reverting on 130 | * overflow. 131 | * 132 | * Counterpart to Solidity's `+` operator. 133 | * 134 | * Requirements: 135 | * - Addition cannot overflow. 136 | */ 137 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 138 | uint256 c = a + b; 139 | require(c >= a, "SafeMath: addition overflow"); 140 | 141 | return c; 142 | } 143 | 144 | /** 145 | * @dev Returns the subtraction of two unsigned integers, reverting on 146 | * overflow (when the result is negative). 147 | * 148 | * Counterpart to Solidity's `-` operator. 149 | * 150 | * Requirements: 151 | * - Subtraction cannot overflow. 152 | */ 153 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 154 | return sub(a, b, "SafeMath: subtraction overflow"); 155 | } 156 | 157 | /** 158 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 159 | * overflow (when the result is negative). 160 | * 161 | * Counterpart to Solidity's `-` operator. 162 | * 163 | * Requirements: 164 | * - Subtraction cannot overflow. 165 | * 166 | * _Available since v2.4.0._ 167 | */ 168 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 169 | require(b <= a, errorMessage); 170 | uint256 c = a - b; 171 | 172 | return c; 173 | } 174 | 175 | /** 176 | * @dev Returns the multiplication of two unsigned integers, reverting on 177 | * overflow. 178 | * 179 | * Counterpart to Solidity's `*` operator. 180 | * 181 | * Requirements: 182 | * - Multiplication cannot overflow. 183 | */ 184 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 185 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 186 | // benefit is lost if 'b' is also tested. 187 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 188 | if (a == 0) { 189 | return 0; 190 | } 191 | 192 | uint256 c = a * b; 193 | require(c / a == b, "SafeMath: multiplication overflow"); 194 | 195 | return c; 196 | } 197 | 198 | /** 199 | * @dev Returns the integer division of two unsigned integers. Reverts on 200 | * division by zero. The result is rounded towards zero. 201 | * 202 | * Counterpart to Solidity's `/` operator. Note: this function uses a 203 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 204 | * uses an invalid opcode to revert (consuming all remaining gas). 205 | * 206 | * Requirements: 207 | * - The divisor cannot be zero. 208 | */ 209 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 210 | return div(a, b, "SafeMath: division by zero"); 211 | } 212 | 213 | /** 214 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 215 | * division by zero. The result is rounded towards zero. 216 | * 217 | * Counterpart to Solidity's `/` operator. Note: this function uses a 218 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 219 | * uses an invalid opcode to revert (consuming all remaining gas). 220 | * 221 | * Requirements: 222 | * - The divisor cannot be zero. 223 | * 224 | * _Available since v2.4.0._ 225 | */ 226 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 227 | // Solidity only automatically asserts when dividing by 0 228 | require(b > 0, errorMessage); 229 | uint256 c = a / b; 230 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 231 | 232 | return c; 233 | } 234 | 235 | /** 236 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 237 | * Reverts when dividing by zero. 238 | * 239 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 240 | * opcode (which leaves remaining gas untouched) while Solidity uses an 241 | * invalid opcode to revert (consuming all remaining gas). 242 | * 243 | * Requirements: 244 | * - The divisor cannot be zero. 245 | */ 246 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 247 | return mod(a, b, "SafeMath: modulo by zero"); 248 | } 249 | 250 | /** 251 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 252 | * Reverts with custom message when dividing by zero. 253 | * 254 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 255 | * opcode (which leaves remaining gas untouched) while Solidity uses an 256 | * invalid opcode to revert (consuming all remaining gas). 257 | * 258 | * Requirements: 259 | * - The divisor cannot be zero. 260 | * 261 | * _Available since v2.4.0._ 262 | */ 263 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 264 | require(b != 0, errorMessage); 265 | return a % b; 266 | } 267 | } 268 | 269 | // File: @openzeppelin/contracts/token/ERC20/ERC20.sol 270 | 271 | pragma solidity ^0.5.0; 272 | 273 | 274 | 275 | 276 | /** 277 | * @dev Implementation of the {IERC20} interface. 278 | * 279 | * This implementation is agnostic to the way tokens are created. This means 280 | * that a supply mechanism has to be added in a derived contract using {_mint}. 281 | * For a generic mechanism see {ERC20Mintable}. 282 | * 283 | * TIP: For a detailed writeup see our guide 284 | * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How 285 | * to implement supply mechanisms]. 286 | * 287 | * We have followed general OpenZeppelin guidelines: functions revert instead 288 | * of returning `false` on failure. This behavior is nonetheless conventional 289 | * and does not conflict with the expectations of ERC20 applications. 290 | * 291 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 292 | * This allows applications to reconstruct the allowance for all accounts just 293 | * by listening to said events. Other implementations of the EIP may not emit 294 | * these events, as it isn't required by the specification. 295 | * 296 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 297 | * functions have been added to mitigate the well-known issues around setting 298 | * allowances. See {IERC20-approve}. 299 | */ 300 | contract ERC20 is Context, IERC20 { 301 | using SafeMath for uint256; 302 | 303 | mapping (address => uint256) private _balances; 304 | 305 | mapping (address => mapping (address => uint256)) private _allowances; 306 | 307 | uint256 private _totalSupply; 308 | 309 | /** 310 | * @dev See {IERC20-totalSupply}. 311 | */ 312 | function totalSupply() public view returns (uint256) { 313 | return _totalSupply; 314 | } 315 | 316 | /** 317 | * @dev See {IERC20-balanceOf}. 318 | */ 319 | function balanceOf(address account) public view returns (uint256) { 320 | return _balances[account]; 321 | } 322 | 323 | /** 324 | * @dev See {IERC20-transfer}. 325 | * 326 | * Requirements: 327 | * 328 | * - `recipient` cannot be the zero address. 329 | * - the caller must have a balance of at least `amount`. 330 | */ 331 | function transfer(address recipient, uint256 amount) public returns (bool) { 332 | _transfer(_msgSender(), recipient, amount); 333 | return true; 334 | } 335 | 336 | /** 337 | * @dev See {IERC20-allowance}. 338 | */ 339 | function allowance(address owner, address spender) public view returns (uint256) { 340 | return _allowances[owner][spender]; 341 | } 342 | 343 | /** 344 | * @dev See {IERC20-approve}. 345 | * 346 | * Requirements: 347 | * 348 | * - `spender` cannot be the zero address. 349 | */ 350 | function approve(address spender, uint256 amount) public returns (bool) { 351 | _approve(_msgSender(), spender, amount); 352 | return true; 353 | } 354 | 355 | /** 356 | * @dev See {IERC20-transferFrom}. 357 | * 358 | * Emits an {Approval} event indicating the updated allowance. This is not 359 | * required by the EIP. See the note at the beginning of {ERC20}; 360 | * 361 | * Requirements: 362 | * - `sender` and `recipient` cannot be the zero address. 363 | * - `sender` must have a balance of at least `amount`. 364 | * - the caller must have allowance for `sender`'s tokens of at least 365 | * `amount`. 366 | */ 367 | function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) { 368 | _transfer(sender, recipient, amount); 369 | _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 370 | return true; 371 | } 372 | 373 | /** 374 | * @dev Atomically increases the allowance granted to `spender` by the caller. 375 | * 376 | * This is an alternative to {approve} that can be used as a mitigation for 377 | * problems described in {IERC20-approve}. 378 | * 379 | * Emits an {Approval} event indicating the updated allowance. 380 | * 381 | * Requirements: 382 | * 383 | * - `spender` cannot be the zero address. 384 | */ 385 | function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { 386 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 387 | return true; 388 | } 389 | 390 | /** 391 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 392 | * 393 | * This is an alternative to {approve} that can be used as a mitigation for 394 | * problems described in {IERC20-approve}. 395 | * 396 | * Emits an {Approval} event indicating the updated allowance. 397 | * 398 | * Requirements: 399 | * 400 | * - `spender` cannot be the zero address. 401 | * - `spender` must have allowance for the caller of at least 402 | * `subtractedValue`. 403 | */ 404 | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { 405 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); 406 | return true; 407 | } 408 | 409 | /** 410 | * @dev Moves tokens `amount` from `sender` to `recipient`. 411 | * 412 | * This is internal function is equivalent to {transfer}, and can be used to 413 | * e.g. implement automatic token fees, slashing mechanisms, etc. 414 | * 415 | * Emits a {Transfer} event. 416 | * 417 | * Requirements: 418 | * 419 | * - `sender` cannot be the zero address. 420 | * - `recipient` cannot be the zero address. 421 | * - `sender` must have a balance of at least `amount`. 422 | */ 423 | function _transfer(address sender, address recipient, uint256 amount) internal { 424 | require(sender != address(0), "ERC20: transfer from the zero address"); 425 | require(recipient != address(0), "ERC20: transfer to the zero address"); 426 | 427 | _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); 428 | _balances[recipient] = _balances[recipient].add(amount); 429 | emit Transfer(sender, recipient, amount); 430 | } 431 | 432 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 433 | * the total supply. 434 | * 435 | * Emits a {Transfer} event with `from` set to the zero address. 436 | * 437 | * Requirements 438 | * 439 | * - `to` cannot be the zero address. 440 | */ 441 | function _mint(address account, uint256 amount) internal { 442 | require(account != address(0), "ERC20: mint to the zero address"); 443 | 444 | _totalSupply = _totalSupply.add(amount); 445 | _balances[account] = _balances[account].add(amount); 446 | emit Transfer(address(0), account, amount); 447 | } 448 | 449 | /** 450 | * @dev Destroys `amount` tokens from `account`, reducing the 451 | * total supply. 452 | * 453 | * Emits a {Transfer} event with `to` set to the zero address. 454 | * 455 | * Requirements 456 | * 457 | * - `account` cannot be the zero address. 458 | * - `account` must have at least `amount` tokens. 459 | */ 460 | function _burn(address account, uint256 amount) internal { 461 | require(account != address(0), "ERC20: burn from the zero address"); 462 | 463 | _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); 464 | _totalSupply = _totalSupply.sub(amount); 465 | emit Transfer(account, address(0), amount); 466 | } 467 | 468 | /** 469 | * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. 470 | * 471 | * This is internal function is equivalent to `approve`, and can be used to 472 | * e.g. set automatic allowances for certain subsystems, etc. 473 | * 474 | * Emits an {Approval} event. 475 | * 476 | * Requirements: 477 | * 478 | * - `owner` cannot be the zero address. 479 | * - `spender` cannot be the zero address. 480 | */ 481 | function _approve(address owner, address spender, uint256 amount) internal { 482 | require(owner != address(0), "ERC20: approve from the zero address"); 483 | require(spender != address(0), "ERC20: approve to the zero address"); 484 | 485 | _allowances[owner][spender] = amount; 486 | emit Approval(owner, spender, amount); 487 | } 488 | 489 | /** 490 | * @dev Destroys `amount` tokens from `account`.`amount` is then deducted 491 | * from the caller's allowance. 492 | * 493 | * See {_burn} and {_approve}. 494 | */ 495 | function _burnFrom(address account, uint256 amount) internal { 496 | _burn(account, amount); 497 | _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance")); 498 | } 499 | } 500 | 501 | // File: @openzeppelin/contracts/token/ERC20/ERC20Burnable.sol 502 | 503 | pragma solidity ^0.5.0; 504 | 505 | 506 | 507 | /** 508 | * @dev Extension of {ERC20} that allows token holders to destroy both their own 509 | * tokens and those that they have an allowance for, in a way that can be 510 | * recognized off-chain (via event analysis). 511 | */ 512 | contract ERC20Burnable is Context, ERC20 { 513 | /** 514 | * @dev Destroys `amount` tokens from the caller. 515 | * 516 | * See {ERC20-_burn}. 517 | */ 518 | function burn(uint256 amount) public { 519 | _burn(_msgSender(), amount); 520 | } 521 | 522 | /** 523 | * @dev See {ERC20-_burnFrom}. 524 | */ 525 | function burnFrom(address account, uint256 amount) public { 526 | _burnFrom(account, amount); 527 | } 528 | } 529 | 530 | // File: contracts/GovernorToken.sol 531 | 532 | // contracts/GovernorToken.sol 533 | // SPDX-License-Identifier: MIT 534 | pragma solidity ^0.5.0; 535 | 536 | 537 | 538 | contract GovernorToken is ERC20, ERC20Burnable { 539 | string public name; 540 | string public symbol; 541 | uint8 public decimals; 542 | constructor() public { 543 | name = "Governor"; 544 | symbol = "GDAO"; 545 | decimals = 18; 546 | _mint(msg.sender, 3000000*1e18); 547 | } 548 | } -------------------------------------------------------------------------------- /gdao/flats/FlatSynLPToken.sol: -------------------------------------------------------------------------------- 1 | // File: @openzeppelin/contracts/GSN/Context.sol 2 | 3 | pragma solidity ^0.5.0; 4 | 5 | /* 6 | * @dev Provides information about the current execution context, including the 7 | * sender of the transaction and its data. While these are generally available 8 | * via msg.sender and msg.data, they should not be accessed in such a direct 9 | * manner, since when dealing with GSN meta-transactions the account sending and 10 | * paying for execution may not be the actual sender (as far as an application 11 | * is concerned). 12 | * 13 | * This contract is only required for intermediate, library-like contracts. 14 | */ 15 | contract Context { 16 | // Empty internal constructor, to prevent people from mistakenly deploying 17 | // an instance of this contract, which should be used via inheritance. 18 | constructor () internal { } 19 | // solhint-disable-previous-line no-empty-blocks 20 | 21 | function _msgSender() internal view returns (address payable) { 22 | return msg.sender; 23 | } 24 | 25 | function _msgData() internal view returns (bytes memory) { 26 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 27 | return msg.data; 28 | } 29 | } 30 | 31 | // File: @openzeppelin/contracts/token/ERC20/IERC20.sol 32 | 33 | pragma solidity ^0.5.0; 34 | 35 | /** 36 | * @dev Interface of the ERC20 standard as defined in the EIP. Does not include 37 | * the optional functions; to access them see {ERC20Detailed}. 38 | */ 39 | interface IERC20 { 40 | /** 41 | * @dev Returns the amount of tokens in existence. 42 | */ 43 | function totalSupply() external view returns (uint256); 44 | 45 | /** 46 | * @dev Returns the amount of tokens owned by `account`. 47 | */ 48 | function balanceOf(address account) external view returns (uint256); 49 | 50 | /** 51 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 52 | * 53 | * Returns a boolean value indicating whether the operation succeeded. 54 | * 55 | * Emits a {Transfer} event. 56 | */ 57 | function transfer(address recipient, uint256 amount) external returns (bool); 58 | 59 | /** 60 | * @dev Returns the remaining number of tokens that `spender` will be 61 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 62 | * zero by default. 63 | * 64 | * This value changes when {approve} or {transferFrom} are called. 65 | */ 66 | function allowance(address owner, address spender) external view returns (uint256); 67 | 68 | /** 69 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 70 | * 71 | * Returns a boolean value indicating whether the operation succeeded. 72 | * 73 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 74 | * that someone may use both the old and the new allowance by unfortunate 75 | * transaction ordering. One possible solution to mitigate this race 76 | * condition is to first reduce the spender's allowance to 0 and set the 77 | * desired value afterwards: 78 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 79 | * 80 | * Emits an {Approval} event. 81 | */ 82 | function approve(address spender, uint256 amount) external returns (bool); 83 | 84 | /** 85 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 86 | * allowance mechanism. `amount` is then deducted from the caller's 87 | * allowance. 88 | * 89 | * Returns a boolean value indicating whether the operation succeeded. 90 | * 91 | * Emits a {Transfer} event. 92 | */ 93 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 94 | 95 | /** 96 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 97 | * another (`to`). 98 | * 99 | * Note that `value` may be zero. 100 | */ 101 | event Transfer(address indexed from, address indexed to, uint256 value); 102 | 103 | /** 104 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 105 | * a call to {approve}. `value` is the new allowance. 106 | */ 107 | event Approval(address indexed owner, address indexed spender, uint256 value); 108 | } 109 | 110 | // File: @openzeppelin/contracts/math/SafeMath.sol 111 | 112 | pragma solidity ^0.5.0; 113 | 114 | /** 115 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 116 | * checks. 117 | * 118 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 119 | * in bugs, because programmers usually assume that an overflow raises an 120 | * error, which is the standard behavior in high level programming languages. 121 | * `SafeMath` restores this intuition by reverting the transaction when an 122 | * operation overflows. 123 | * 124 | * Using this library instead of the unchecked operations eliminates an entire 125 | * class of bugs, so it's recommended to use it always. 126 | */ 127 | library SafeMath { 128 | /** 129 | * @dev Returns the addition of two unsigned integers, reverting on 130 | * overflow. 131 | * 132 | * Counterpart to Solidity's `+` operator. 133 | * 134 | * Requirements: 135 | * - Addition cannot overflow. 136 | */ 137 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 138 | uint256 c = a + b; 139 | require(c >= a, "SafeMath: addition overflow"); 140 | 141 | return c; 142 | } 143 | 144 | /** 145 | * @dev Returns the subtraction of two unsigned integers, reverting on 146 | * overflow (when the result is negative). 147 | * 148 | * Counterpart to Solidity's `-` operator. 149 | * 150 | * Requirements: 151 | * - Subtraction cannot overflow. 152 | */ 153 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 154 | return sub(a, b, "SafeMath: subtraction overflow"); 155 | } 156 | 157 | /** 158 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 159 | * overflow (when the result is negative). 160 | * 161 | * Counterpart to Solidity's `-` operator. 162 | * 163 | * Requirements: 164 | * - Subtraction cannot overflow. 165 | * 166 | * _Available since v2.4.0._ 167 | */ 168 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 169 | require(b <= a, errorMessage); 170 | uint256 c = a - b; 171 | 172 | return c; 173 | } 174 | 175 | /** 176 | * @dev Returns the multiplication of two unsigned integers, reverting on 177 | * overflow. 178 | * 179 | * Counterpart to Solidity's `*` operator. 180 | * 181 | * Requirements: 182 | * - Multiplication cannot overflow. 183 | */ 184 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 185 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 186 | // benefit is lost if 'b' is also tested. 187 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 188 | if (a == 0) { 189 | return 0; 190 | } 191 | 192 | uint256 c = a * b; 193 | require(c / a == b, "SafeMath: multiplication overflow"); 194 | 195 | return c; 196 | } 197 | 198 | /** 199 | * @dev Returns the integer division of two unsigned integers. Reverts on 200 | * division by zero. The result is rounded towards zero. 201 | * 202 | * Counterpart to Solidity's `/` operator. Note: this function uses a 203 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 204 | * uses an invalid opcode to revert (consuming all remaining gas). 205 | * 206 | * Requirements: 207 | * - The divisor cannot be zero. 208 | */ 209 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 210 | return div(a, b, "SafeMath: division by zero"); 211 | } 212 | 213 | /** 214 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 215 | * division by zero. The result is rounded towards zero. 216 | * 217 | * Counterpart to Solidity's `/` operator. Note: this function uses a 218 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 219 | * uses an invalid opcode to revert (consuming all remaining gas). 220 | * 221 | * Requirements: 222 | * - The divisor cannot be zero. 223 | * 224 | * _Available since v2.4.0._ 225 | */ 226 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 227 | // Solidity only automatically asserts when dividing by 0 228 | require(b > 0, errorMessage); 229 | uint256 c = a / b; 230 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 231 | 232 | return c; 233 | } 234 | 235 | /** 236 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 237 | * Reverts when dividing by zero. 238 | * 239 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 240 | * opcode (which leaves remaining gas untouched) while Solidity uses an 241 | * invalid opcode to revert (consuming all remaining gas). 242 | * 243 | * Requirements: 244 | * - The divisor cannot be zero. 245 | */ 246 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 247 | return mod(a, b, "SafeMath: modulo by zero"); 248 | } 249 | 250 | /** 251 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 252 | * Reverts with custom message when dividing by zero. 253 | * 254 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 255 | * opcode (which leaves remaining gas untouched) while Solidity uses an 256 | * invalid opcode to revert (consuming all remaining gas). 257 | * 258 | * Requirements: 259 | * - The divisor cannot be zero. 260 | * 261 | * _Available since v2.4.0._ 262 | */ 263 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 264 | require(b != 0, errorMessage); 265 | return a % b; 266 | } 267 | } 268 | 269 | // File: @openzeppelin/contracts/token/ERC20/ERC20.sol 270 | 271 | pragma solidity ^0.5.0; 272 | 273 | 274 | 275 | 276 | /** 277 | * @dev Implementation of the {IERC20} interface. 278 | * 279 | * This implementation is agnostic to the way tokens are created. This means 280 | * that a supply mechanism has to be added in a derived contract using {_mint}. 281 | * For a generic mechanism see {ERC20Mintable}. 282 | * 283 | * TIP: For a detailed writeup see our guide 284 | * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How 285 | * to implement supply mechanisms]. 286 | * 287 | * We have followed general OpenZeppelin guidelines: functions revert instead 288 | * of returning `false` on failure. This behavior is nonetheless conventional 289 | * and does not conflict with the expectations of ERC20 applications. 290 | * 291 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 292 | * This allows applications to reconstruct the allowance for all accounts just 293 | * by listening to said events. Other implementations of the EIP may not emit 294 | * these events, as it isn't required by the specification. 295 | * 296 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 297 | * functions have been added to mitigate the well-known issues around setting 298 | * allowances. See {IERC20-approve}. 299 | */ 300 | contract ERC20 is Context, IERC20 { 301 | using SafeMath for uint256; 302 | 303 | mapping (address => uint256) private _balances; 304 | 305 | mapping (address => mapping (address => uint256)) private _allowances; 306 | 307 | uint256 private _totalSupply; 308 | 309 | /** 310 | * @dev See {IERC20-totalSupply}. 311 | */ 312 | function totalSupply() public view returns (uint256) { 313 | return _totalSupply; 314 | } 315 | 316 | /** 317 | * @dev See {IERC20-balanceOf}. 318 | */ 319 | function balanceOf(address account) public view returns (uint256) { 320 | return _balances[account]; 321 | } 322 | 323 | /** 324 | * @dev See {IERC20-transfer}. 325 | * 326 | * Requirements: 327 | * 328 | * - `recipient` cannot be the zero address. 329 | * - the caller must have a balance of at least `amount`. 330 | */ 331 | function transfer(address recipient, uint256 amount) public returns (bool) { 332 | _transfer(_msgSender(), recipient, amount); 333 | return true; 334 | } 335 | 336 | /** 337 | * @dev See {IERC20-allowance}. 338 | */ 339 | function allowance(address owner, address spender) public view returns (uint256) { 340 | return _allowances[owner][spender]; 341 | } 342 | 343 | /** 344 | * @dev See {IERC20-approve}. 345 | * 346 | * Requirements: 347 | * 348 | * - `spender` cannot be the zero address. 349 | */ 350 | function approve(address spender, uint256 amount) public returns (bool) { 351 | _approve(_msgSender(), spender, amount); 352 | return true; 353 | } 354 | 355 | /** 356 | * @dev See {IERC20-transferFrom}. 357 | * 358 | * Emits an {Approval} event indicating the updated allowance. This is not 359 | * required by the EIP. See the note at the beginning of {ERC20}; 360 | * 361 | * Requirements: 362 | * - `sender` and `recipient` cannot be the zero address. 363 | * - `sender` must have a balance of at least `amount`. 364 | * - the caller must have allowance for `sender`'s tokens of at least 365 | * `amount`. 366 | */ 367 | function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) { 368 | _transfer(sender, recipient, amount); 369 | _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 370 | return true; 371 | } 372 | 373 | /** 374 | * @dev Atomically increases the allowance granted to `spender` by the caller. 375 | * 376 | * This is an alternative to {approve} that can be used as a mitigation for 377 | * problems described in {IERC20-approve}. 378 | * 379 | * Emits an {Approval} event indicating the updated allowance. 380 | * 381 | * Requirements: 382 | * 383 | * - `spender` cannot be the zero address. 384 | */ 385 | function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { 386 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 387 | return true; 388 | } 389 | 390 | /** 391 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 392 | * 393 | * This is an alternative to {approve} that can be used as a mitigation for 394 | * problems described in {IERC20-approve}. 395 | * 396 | * Emits an {Approval} event indicating the updated allowance. 397 | * 398 | * Requirements: 399 | * 400 | * - `spender` cannot be the zero address. 401 | * - `spender` must have allowance for the caller of at least 402 | * `subtractedValue`. 403 | */ 404 | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { 405 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); 406 | return true; 407 | } 408 | 409 | /** 410 | * @dev Moves tokens `amount` from `sender` to `recipient`. 411 | * 412 | * This is internal function is equivalent to {transfer}, and can be used to 413 | * e.g. implement automatic token fees, slashing mechanisms, etc. 414 | * 415 | * Emits a {Transfer} event. 416 | * 417 | * Requirements: 418 | * 419 | * - `sender` cannot be the zero address. 420 | * - `recipient` cannot be the zero address. 421 | * - `sender` must have a balance of at least `amount`. 422 | */ 423 | function _transfer(address sender, address recipient, uint256 amount) internal { 424 | require(sender != address(0), "ERC20: transfer from the zero address"); 425 | require(recipient != address(0), "ERC20: transfer to the zero address"); 426 | 427 | _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); 428 | _balances[recipient] = _balances[recipient].add(amount); 429 | emit Transfer(sender, recipient, amount); 430 | } 431 | 432 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 433 | * the total supply. 434 | * 435 | * Emits a {Transfer} event with `from` set to the zero address. 436 | * 437 | * Requirements 438 | * 439 | * - `to` cannot be the zero address. 440 | */ 441 | function _mint(address account, uint256 amount) internal { 442 | require(account != address(0), "ERC20: mint to the zero address"); 443 | 444 | _totalSupply = _totalSupply.add(amount); 445 | _balances[account] = _balances[account].add(amount); 446 | emit Transfer(address(0), account, amount); 447 | } 448 | 449 | /** 450 | * @dev Destroys `amount` tokens from `account`, reducing the 451 | * total supply. 452 | * 453 | * Emits a {Transfer} event with `to` set to the zero address. 454 | * 455 | * Requirements 456 | * 457 | * - `account` cannot be the zero address. 458 | * - `account` must have at least `amount` tokens. 459 | */ 460 | function _burn(address account, uint256 amount) internal { 461 | require(account != address(0), "ERC20: burn from the zero address"); 462 | 463 | _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); 464 | _totalSupply = _totalSupply.sub(amount); 465 | emit Transfer(account, address(0), amount); 466 | } 467 | 468 | /** 469 | * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. 470 | * 471 | * This is internal function is equivalent to `approve`, and can be used to 472 | * e.g. set automatic allowances for certain subsystems, etc. 473 | * 474 | * Emits an {Approval} event. 475 | * 476 | * Requirements: 477 | * 478 | * - `owner` cannot be the zero address. 479 | * - `spender` cannot be the zero address. 480 | */ 481 | function _approve(address owner, address spender, uint256 amount) internal { 482 | require(owner != address(0), "ERC20: approve from the zero address"); 483 | require(spender != address(0), "ERC20: approve to the zero address"); 484 | 485 | _allowances[owner][spender] = amount; 486 | emit Approval(owner, spender, amount); 487 | } 488 | 489 | /** 490 | * @dev Destroys `amount` tokens from `account`.`amount` is then deducted 491 | * from the caller's allowance. 492 | * 493 | * See {_burn} and {_approve}. 494 | */ 495 | function _burnFrom(address account, uint256 amount) internal { 496 | _burn(account, amount); 497 | _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance")); 498 | } 499 | } 500 | 501 | // File: @openzeppelin/contracts/token/ERC20/ERC20Burnable.sol 502 | 503 | pragma solidity ^0.5.0; 504 | 505 | 506 | 507 | /** 508 | * @dev Extension of {ERC20} that allows token holders to destroy both their own 509 | * tokens and those that they have an allowance for, in a way that can be 510 | * recognized off-chain (via event analysis). 511 | */ 512 | contract ERC20Burnable is Context, ERC20 { 513 | /** 514 | * @dev Destroys `amount` tokens from the caller. 515 | * 516 | * See {ERC20-_burn}. 517 | */ 518 | function burn(uint256 amount) public { 519 | _burn(_msgSender(), amount); 520 | } 521 | 522 | /** 523 | * @dev See {ERC20-_burnFrom}. 524 | */ 525 | function burnFrom(address account, uint256 amount) public { 526 | _burnFrom(account, amount); 527 | } 528 | } 529 | 530 | // File: contracts/SynLPToken.sol 531 | 532 | // contracts/SynLPToken.sol 533 | // SPDX-License-Identifier: MIT 534 | pragma solidity ^0.5.0; 535 | 536 | 537 | 538 | contract SynLPToken is ERC20, ERC20Burnable { 539 | string public name; 540 | string public symbol; 541 | uint8 public decimals; 542 | constructor() public { 543 | name = "synthetic GDAO-ETH LP V2"; 544 | symbol = "sLP"; 545 | decimals = 18; 546 | _mint(msg.sender, 6710*1e18); 547 | } 548 | } -------------------------------------------------------------------------------- /swapico/flats/synLPToken_flat.sol: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 3 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 4 | //////////////////////////////////////.////////////////////////////////.//////////////////////////////////// 5 | ///////////////////////////////////.@.//////////////////////////////////.@.///////////////////////////////// 6 | ////////////////////////////////.@@.//////////////////////////////////////.@@.////////////////////////////// 7 | /////////////////////////////..@@@.////////////////////////////////////////.@@@../////////////////////////// 8 | ///////////////////////////.@@@@@.//////////////////////////////////////////.@@@@@.///////////////////////// 9 | /////////////////////////.@@@@@@@////////////////////////////////////////////@@@@@@@./////////////////////// 10 | ////////////////////////.@@@@@@@.////////////////////////////////////////////.@@@@@@@.////////////////////// 11 | //////////////////..///.@@@@@@@@//////////////////////////////////////////////@@@@@@@@.///..//////////////// 12 | ////////////////.@@.//.@@@@@@@@@//////////////////////////////////////////////@@@@@@@@@.//.@@.////////////// 13 | ///////////////@@@@.//@@@@@@@@@.//////////////////////////////////////////////.@@@@@@@@@//@@@@@///////////// 14 | //////////////@@@@@@//@@@@@@@@@.//////////////////////////////////////////////.@@@@@@@@@//@@@@@@//////////// 15 | /////////////@@@@@@@./@@@@@@@@@@//////////////////////////////////////////////@@@@@@@@@./.@@@@@@@/////////// 16 | /////////////@@@@@@@@//@@@@@@@@@.////////////////////////////////////////////.@@@@@@@@@//@@@@@@@@/////////// 17 | /////////////@@@@@@@@.//.@@@@@@@@.//////////////////////////////////////////@@@@@@@@@.//.@@@@@@@@/////////// 18 | /////////////@@@@@@@@@///.@@@@@@@@@.////////.//////////////////////////////@@@@@@@@@.///@@@@@@@@@/////////// 19 | /////////////.@@@@@@@@@///..@@@@@@@.////////.@.///////////////////////////.@@@@@@@.////@@@@@@@@@./////////// 20 | //////////////.@@@@@@@@@.////.@@@@///////////.@@.//////////////////////////.@@@@.////.@@@@@@@@@.//////////// 21 | //////////.////.@@@@@@@@@@./////./////////////.@@@@..////////////////////////./////.@@@@@@@@@@.///..//////// 22 | //////////@@.///.@@@@@@@@@@@.//////////////////.@@@@@@@@@@./////////////////////..@@@@@@@@@@.///.@@.//////// 23 | //////////@@@@.///.@@@@@@@@@@@@.////////////////.@@@@@@@@@@@..///////////////.@@@@@@@@@@@@@.//.@@@@.//////// 24 | //////////.@@@@@@.///.@@@@@@@@@@@.///////////////.@@@@@@@@@@@@./////////////.@@@@@@@@@@@.//.@@@@@@@.//////// 25 | //////////.@@@@@@@@.////.@@@@@@@@@.///////////////@@@@@@@@@...@////////////.@@@@@@@@@.//..@@@@@@@@@.//////// 26 | //////////.@@@@@@@@@@@..////..@@@@@@./////////////@@@@@@@@@ /////////////.@@@@@@..///..@@@@@@@@@@@.///////// 27 | ///////////.@@@@@@@@@@@@@@..//////.....///////////@@@@@@@@@.///////////...../////..@@@@@@@@@@@@@@@////////// 28 | ////////////.@@@@@@@@@@@@@@@@@@....///////////////@@@@@@@@@.///////////////...@@@@@@@@@@@@@@@@@@@.////////// 29 | /////////////.@@@@@@@@@@@@@@@@@@@@@@@@@@@..///////@@@@@@@@@@//////....@@@@@@@@@@@@@@@@@@@@@@@@@@./////////// 30 | //////////////.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.///.@@@@@@@@@@/////@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@///////////// 31 | ////////////////.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@///@@@@@@@@@@@.///.@@@@@@@@@@@@@@@@@@@@@@@@@@@@.////////////// 32 | //////////////////.@@@@@@@@@@@@@@@@@@@@@@@@@@@@/@@@@@@@@@@@@@./.@@@@@@@@@@@@@@@@@@@@@@@@@@@.//////////////// 33 | ////////////////////.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..////////////////// 34 | //////////////////////..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.///////////////////// 35 | /////////////////////////..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.//////////////////////// 36 | /////////////////////////////..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@../////////////////////////// 37 | /////////////////////////////////..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@../////////////////////////////// 38 | //////////////////////////////////////...@@@@@@@@@@@@@@@@@@@@@@@@@@@@...//////////////////////////////////// 39 | //////////////////////////////////////////////...@@@@@@@@@@@@@@...////////////////////////////////////////// 40 | //////////////////////////////////////////////////.@@@@@@@@@//////////////////////////////////////////////// 41 | ////////////////////////////////////////////////.@@@@@./@@@@@/////////////////////////////////////////////// 42 | ///////////////////////////////////////////////.@@@@@@///@@@@@.///////////////////////////////////////////// 43 | /////////////////////////////////////////////.@@@@@@@/.@./@@@@@@./////////////////////////////////////////// 44 | ////////////////////////////////////////////@@@@@@@@/.@@@/.@@@@@@@.///////////////////////////////////////// 45 | ///////////////////////////////////////////.@@@@@@@//@@@@@//@@@@@@@.//////////////////////////////////////// 46 | ////////////////////////////////////////////.@@@@@./@@@@@@@/.@@@@@.///////////////////////////////////////// 47 | //////////////////////////////////////////////.@@./@@@@@@@@@/.@@./////////////////////////////////////////// 48 | ///////////////////////////////////////////////../@@@@@@@@@@@/..//////////////////////////////////////////// 49 | /////////////////////////////////////////////////@@@@@@@@@@@@@////////////////////////////////////////////// 50 | ////////////////////////////////////////////////@@@@@@@@@@@@@@@///////////////////////////////////////////// 51 | ///////////////////////////////////////////////@@@@@@.///.@@@@@.//////////////////////////////////////////// 52 | //////////////////////////////////////////////.@@..//.@@..//..@@./////////////////////////////////////////// 53 | /////////////////////////////////////////////..//////@@@@//////...////////////////////////////////////////// 54 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 55 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 56 | /////////////_______///________//____////____//_______//______///////__///__////______////______//////////// 57 | /////////////@@_____|//@@@__@@@\/\@@@\ /@@@//|@@@____||@@@_ \/////|@@\ |@@|/// __ \//|@@@_@@\/////////// 58 | ////////////|@@|//__//|@@| |@@|//\@@@\/@@@///|@@|__///|@@|_) |////|@@@\|@@|/|@@| |@@|/|@@|_)@@|////////// 59 | ////////////|@@| |_@|/|@@| |@@|///\@@@@@@////|@@@__|//|@@@@@@//////|@@.@`@@|/|@@| |@@|/|@@@@@@//////////// 60 | ////////////|@@|__|@|/|@@`--'@@|////\@@@@/////|@@|____/|@@|\@@\----.|@@|\@@@|/|@@`--'@@|/|@@|\@@\----.////// 61 | /////////////\______|//\______///////\__//////|_______|| _| `._____||__| \__|//\______///|@_| `._____|////// 62 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 63 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 64 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 65 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// 66 | 67 | // File: @openzeppelin/contracts/GSN/Context.sol 68 | 69 | pragma solidity ^0.5.0; 70 | 71 | /* 72 | * @dev Provides information about the current execution context, including the 73 | * sender of the transaction and its data. While these are generally available 74 | * via msg.sender and msg.data, they should not be accessed in such a direct 75 | * manner, since when dealing with GSN meta-transactions the account sending and 76 | * paying for execution may not be the actual sender (as far as an application 77 | * is concerned). 78 | * 79 | * This contract is only required for intermediate, library-like contracts. 80 | */ 81 | contract Context { 82 | // Empty internal constructor, to prevent people from mistakenly deploying 83 | // an instance of this contract, which should be used via inheritance. 84 | constructor () internal { } 85 | // solhint-disable-previous-line no-empty-blocks 86 | 87 | function _msgSender() internal view returns (address payable) { 88 | return msg.sender; 89 | } 90 | 91 | function _msgData() internal view returns (bytes memory) { 92 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 93 | return msg.data; 94 | } 95 | } 96 | 97 | // File: @openzeppelin/contracts/token/ERC20/IERC20.sol 98 | 99 | pragma solidity ^0.5.0; 100 | 101 | /** 102 | * @dev Interface of the ERC20 standard as defined in the EIP. Does not include 103 | * the optional functions; to access them see {ERC20Detailed}. 104 | */ 105 | interface IERC20 { 106 | /** 107 | * @dev Returns the amount of tokens in existence. 108 | */ 109 | function totalSupply() external view returns (uint256); 110 | 111 | /** 112 | * @dev Returns the amount of tokens owned by `account`. 113 | */ 114 | function balanceOf(address account) external view returns (uint256); 115 | 116 | /** 117 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 118 | * 119 | * Returns a boolean value indicating whether the operation succeeded. 120 | * 121 | * Emits a {Transfer} event. 122 | */ 123 | function transfer(address recipient, uint256 amount) external returns (bool); 124 | 125 | /** 126 | * @dev Returns the remaining number of tokens that `spender` will be 127 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 128 | * zero by default. 129 | * 130 | * This value changes when {approve} or {transferFrom} are called. 131 | */ 132 | function allowance(address owner, address spender) external view returns (uint256); 133 | 134 | /** 135 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 136 | * 137 | * Returns a boolean value indicating whether the operation succeeded. 138 | * 139 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 140 | * that someone may use both the old and the new allowance by unfortunate 141 | * transaction ordering. One possible solution to mitigate this race 142 | * condition is to first reduce the spender's allowance to 0 and set the 143 | * desired value afterwards: 144 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 145 | * 146 | * Emits an {Approval} event. 147 | */ 148 | function approve(address spender, uint256 amount) external returns (bool); 149 | 150 | /** 151 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 152 | * allowance mechanism. `amount` is then deducted from the caller's 153 | * allowance. 154 | * 155 | * Returns a boolean value indicating whether the operation succeeded. 156 | * 157 | * Emits a {Transfer} event. 158 | */ 159 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 160 | 161 | /** 162 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 163 | * another (`to`). 164 | * 165 | * Note that `value` may be zero. 166 | */ 167 | event Transfer(address indexed from, address indexed to, uint256 value); 168 | 169 | /** 170 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 171 | * a call to {approve}. `value` is the new allowance. 172 | */ 173 | event Approval(address indexed owner, address indexed spender, uint256 value); 174 | } 175 | 176 | // File: @openzeppelin/contracts/math/SafeMath.sol 177 | 178 | pragma solidity ^0.5.0; 179 | 180 | /** 181 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 182 | * checks. 183 | * 184 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 185 | * in bugs, because programmers usually assume that an overflow raises an 186 | * error, which is the standard behavior in high level programming languages. 187 | * `SafeMath` restores this intuition by reverting the transaction when an 188 | * operation overflows. 189 | * 190 | * Using this library instead of the unchecked operations eliminates an entire 191 | * class of bugs, so it's recommended to use it always. 192 | */ 193 | library SafeMath { 194 | /** 195 | * @dev Returns the addition of two unsigned integers, reverting on 196 | * overflow. 197 | * 198 | * Counterpart to Solidity's `+` operator. 199 | * 200 | * Requirements: 201 | * - Addition cannot overflow. 202 | */ 203 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 204 | uint256 c = a + b; 205 | require(c >= a, "SafeMath: addition overflow"); 206 | 207 | return c; 208 | } 209 | 210 | /** 211 | * @dev Returns the subtraction of two unsigned integers, reverting on 212 | * overflow (when the result is negative). 213 | * 214 | * Counterpart to Solidity's `-` operator. 215 | * 216 | * Requirements: 217 | * - Subtraction cannot overflow. 218 | */ 219 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 220 | return sub(a, b, "SafeMath: subtraction overflow"); 221 | } 222 | 223 | /** 224 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 225 | * overflow (when the result is negative). 226 | * 227 | * Counterpart to Solidity's `-` operator. 228 | * 229 | * Requirements: 230 | * - Subtraction cannot overflow. 231 | * 232 | * _Available since v2.4.0._ 233 | */ 234 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 235 | require(b <= a, errorMessage); 236 | uint256 c = a - b; 237 | 238 | return c; 239 | } 240 | 241 | /** 242 | * @dev Returns the multiplication of two unsigned integers, reverting on 243 | * overflow. 244 | * 245 | * Counterpart to Solidity's `*` operator. 246 | * 247 | * Requirements: 248 | * - Multiplication cannot overflow. 249 | */ 250 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 251 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 252 | // benefit is lost if 'b' is also tested. 253 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 254 | if (a == 0) { 255 | return 0; 256 | } 257 | 258 | uint256 c = a * b; 259 | require(c / a == b, "SafeMath: multiplication overflow"); 260 | 261 | return c; 262 | } 263 | 264 | /** 265 | * @dev Returns the integer division of two unsigned integers. Reverts on 266 | * division by zero. The result is rounded towards zero. 267 | * 268 | * Counterpart to Solidity's `/` operator. Note: this function uses a 269 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 270 | * uses an invalid opcode to revert (consuming all remaining gas). 271 | * 272 | * Requirements: 273 | * - The divisor cannot be zero. 274 | */ 275 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 276 | return div(a, b, "SafeMath: division by zero"); 277 | } 278 | 279 | /** 280 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 281 | * division by zero. The result is rounded towards zero. 282 | * 283 | * Counterpart to Solidity's `/` operator. Note: this function uses a 284 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 285 | * uses an invalid opcode to revert (consuming all remaining gas). 286 | * 287 | * Requirements: 288 | * - The divisor cannot be zero. 289 | * 290 | * _Available since v2.4.0._ 291 | */ 292 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 293 | // Solidity only automatically asserts when dividing by 0 294 | require(b > 0, errorMessage); 295 | uint256 c = a / b; 296 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 297 | 298 | return c; 299 | } 300 | 301 | /** 302 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 303 | * Reverts when dividing by zero. 304 | * 305 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 306 | * opcode (which leaves remaining gas untouched) while Solidity uses an 307 | * invalid opcode to revert (consuming all remaining gas). 308 | * 309 | * Requirements: 310 | * - The divisor cannot be zero. 311 | */ 312 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 313 | return mod(a, b, "SafeMath: modulo by zero"); 314 | } 315 | 316 | /** 317 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 318 | * Reverts with custom message when dividing by zero. 319 | * 320 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 321 | * opcode (which leaves remaining gas untouched) while Solidity uses an 322 | * invalid opcode to revert (consuming all remaining gas). 323 | * 324 | * Requirements: 325 | * - The divisor cannot be zero. 326 | * 327 | * _Available since v2.4.0._ 328 | */ 329 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 330 | require(b != 0, errorMessage); 331 | return a % b; 332 | } 333 | } 334 | 335 | // File: @openzeppelin/contracts/token/ERC20/ERC20.sol 336 | 337 | pragma solidity ^0.5.0; 338 | 339 | 340 | 341 | 342 | /** 343 | * @dev Implementation of the {IERC20} interface. 344 | * 345 | * This implementation is agnostic to the way tokens are created. This means 346 | * that a supply mechanism has to be added in a derived contract using {_mint}. 347 | * For a generic mechanism see {ERC20Mintable}. 348 | * 349 | * TIP: For a detailed writeup see our guide 350 | * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How 351 | * to implement supply mechanisms]. 352 | * 353 | * We have followed general OpenZeppelin guidelines: functions revert instead 354 | * of returning `false` on failure. This behavior is nonetheless conventional 355 | * and does not conflict with the expectations of ERC20 applications. 356 | * 357 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 358 | * This allows applications to reconstruct the allowance for all accounts just 359 | * by listening to said events. Other implementations of the EIP may not emit 360 | * these events, as it isn't required by the specification. 361 | * 362 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 363 | * functions have been added to mitigate the well-known issues around setting 364 | * allowances. See {IERC20-approve}. 365 | */ 366 | contract ERC20 is Context, IERC20 { 367 | using SafeMath for uint256; 368 | 369 | mapping (address => uint256) private _balances; 370 | 371 | mapping (address => mapping (address => uint256)) private _allowances; 372 | 373 | uint256 private _totalSupply; 374 | 375 | /** 376 | * @dev See {IERC20-totalSupply}. 377 | */ 378 | function totalSupply() public view returns (uint256) { 379 | return _totalSupply; 380 | } 381 | 382 | /** 383 | * @dev See {IERC20-balanceOf}. 384 | */ 385 | function balanceOf(address account) public view returns (uint256) { 386 | return _balances[account]; 387 | } 388 | 389 | /** 390 | * @dev See {IERC20-transfer}. 391 | * 392 | * Requirements: 393 | * 394 | * - `recipient` cannot be the zero address. 395 | * - the caller must have a balance of at least `amount`. 396 | */ 397 | function transfer(address recipient, uint256 amount) public returns (bool) { 398 | _transfer(_msgSender(), recipient, amount); 399 | return true; 400 | } 401 | 402 | /** 403 | * @dev See {IERC20-allowance}. 404 | */ 405 | function allowance(address owner, address spender) public view returns (uint256) { 406 | return _allowances[owner][spender]; 407 | } 408 | 409 | /** 410 | * @dev See {IERC20-approve}. 411 | * 412 | * Requirements: 413 | * 414 | * - `spender` cannot be the zero address. 415 | */ 416 | function approve(address spender, uint256 amount) public returns (bool) { 417 | _approve(_msgSender(), spender, amount); 418 | return true; 419 | } 420 | 421 | /** 422 | * @dev See {IERC20-transferFrom}. 423 | * 424 | * Emits an {Approval} event indicating the updated allowance. This is not 425 | * required by the EIP. See the note at the beginning of {ERC20}; 426 | * 427 | * Requirements: 428 | * - `sender` and `recipient` cannot be the zero address. 429 | * - `sender` must have a balance of at least `amount`. 430 | * - the caller must have allowance for `sender`'s tokens of at least 431 | * `amount`. 432 | */ 433 | function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) { 434 | _transfer(sender, recipient, amount); 435 | _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 436 | return true; 437 | } 438 | 439 | /** 440 | * @dev Atomically increases the allowance granted to `spender` by the caller. 441 | * 442 | * This is an alternative to {approve} that can be used as a mitigation for 443 | * problems described in {IERC20-approve}. 444 | * 445 | * Emits an {Approval} event indicating the updated allowance. 446 | * 447 | * Requirements: 448 | * 449 | * - `spender` cannot be the zero address. 450 | */ 451 | function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { 452 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 453 | return true; 454 | } 455 | 456 | /** 457 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 458 | * 459 | * This is an alternative to {approve} that can be used as a mitigation for 460 | * problems described in {IERC20-approve}. 461 | * 462 | * Emits an {Approval} event indicating the updated allowance. 463 | * 464 | * Requirements: 465 | * 466 | * - `spender` cannot be the zero address. 467 | * - `spender` must have allowance for the caller of at least 468 | * `subtractedValue`. 469 | */ 470 | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { 471 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); 472 | return true; 473 | } 474 | 475 | /** 476 | * @dev Moves tokens `amount` from `sender` to `recipient`. 477 | * 478 | * This is internal function is equivalent to {transfer}, and can be used to 479 | * e.g. implement automatic token fees, slashing mechanisms, etc. 480 | * 481 | * Emits a {Transfer} event. 482 | * 483 | * Requirements: 484 | * 485 | * - `sender` cannot be the zero address. 486 | * - `recipient` cannot be the zero address. 487 | * - `sender` must have a balance of at least `amount`. 488 | */ 489 | function _transfer(address sender, address recipient, uint256 amount) internal { 490 | require(sender != address(0), "ERC20: transfer from the zero address"); 491 | require(recipient != address(0), "ERC20: transfer to the zero address"); 492 | 493 | _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); 494 | _balances[recipient] = _balances[recipient].add(amount); 495 | emit Transfer(sender, recipient, amount); 496 | } 497 | 498 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 499 | * the total supply. 500 | * 501 | * Emits a {Transfer} event with `from` set to the zero address. 502 | * 503 | * Requirements 504 | * 505 | * - `to` cannot be the zero address. 506 | */ 507 | function _mint(address account, uint256 amount) internal { 508 | require(account != address(0), "ERC20: mint to the zero address"); 509 | 510 | _totalSupply = _totalSupply.add(amount); 511 | _balances[account] = _balances[account].add(amount); 512 | emit Transfer(address(0), account, amount); 513 | } 514 | 515 | /** 516 | * @dev Destroys `amount` tokens from `account`, reducing the 517 | * total supply. 518 | * 519 | * Emits a {Transfer} event with `to` set to the zero address. 520 | * 521 | * Requirements 522 | * 523 | * - `account` cannot be the zero address. 524 | * - `account` must have at least `amount` tokens. 525 | */ 526 | function _burn(address account, uint256 amount) internal { 527 | require(account != address(0), "ERC20: burn from the zero address"); 528 | 529 | _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); 530 | _totalSupply = _totalSupply.sub(amount); 531 | emit Transfer(account, address(0), amount); 532 | } 533 | 534 | /** 535 | * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. 536 | * 537 | * This is internal function is equivalent to `approve`, and can be used to 538 | * e.g. set automatic allowances for certain subsystems, etc. 539 | * 540 | * Emits an {Approval} event. 541 | * 542 | * Requirements: 543 | * 544 | * - `owner` cannot be the zero address. 545 | * - `spender` cannot be the zero address. 546 | */ 547 | function _approve(address owner, address spender, uint256 amount) internal { 548 | require(owner != address(0), "ERC20: approve from the zero address"); 549 | require(spender != address(0), "ERC20: approve to the zero address"); 550 | 551 | _allowances[owner][spender] = amount; 552 | emit Approval(owner, spender, amount); 553 | } 554 | 555 | /** 556 | * @dev Destroys `amount` tokens from `account`.`amount` is then deducted 557 | * from the caller's allowance. 558 | * 559 | * See {_burn} and {_approve}. 560 | */ 561 | function _burnFrom(address account, uint256 amount) internal { 562 | _burn(account, amount); 563 | _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance")); 564 | } 565 | } 566 | 567 | // File: @openzeppelin/contracts/token/ERC20/ERC20Burnable.sol 568 | 569 | pragma solidity ^0.5.0; 570 | 571 | 572 | 573 | /** 574 | * @dev Extension of {ERC20} that allows token holders to destroy both their own 575 | * tokens and those that they have an allowance for, in a way that can be 576 | * recognized off-chain (via event analysis). 577 | */ 578 | contract ERC20Burnable is Context, ERC20 { 579 | /** 580 | * @dev Destroys `amount` tokens from the caller. 581 | * 582 | * See {ERC20-_burn}. 583 | */ 584 | function burn(uint256 amount) public { 585 | _burn(_msgSender(), amount); 586 | } 587 | 588 | /** 589 | * @dev See {ERC20-_burnFrom}. 590 | */ 591 | function burnFrom(address account, uint256 amount) public { 592 | _burnFrom(account, amount); 593 | } 594 | } 595 | 596 | // File: contracts/SynLPToken.sol 597 | 598 | // contracts/SynLPToken.sol 599 | // SPDX-License-Identifier: MIT 600 | pragma solidity ^0.5.0; 601 | 602 | 603 | 604 | contract SynLPToken is ERC20, ERC20Burnable { 605 | string public name; 606 | string public symbol; 607 | uint8 public decimals; 608 | constructor() public { 609 | name = "synthetic GDAO-ETH LP V2"; 610 | symbol = "sLP"; 611 | decimals = 18; 612 | _mint(msg.sender, 6710*1e18); 613 | } 614 | } -------------------------------------------------------------------------------- /merkle-distributor/LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------