From bf6fc5f7ba63a87637afe70b678c371d344ad9ea Mon Sep 17 00:00:00 2001 From: Louis Myself <louismemyself@gmail.com> Date: Fri, 25 Mar 2022 21:11:41 +0100 Subject: [PATCH] deployment files --- deployments/avalanche/FarmLensV2.json | 76 +++-- .../05be5b065453cde7967331fef060caff.json | 274 ++++++++++++++++++ deployments/rinkeby/FarmLensV2.json | 78 +++-- .../05be5b065453cde7967331fef060caff.json | 274 ++++++++++++++++++ 4 files changed, 655 insertions(+), 47 deletions(-) create mode 100644 deployments/avalanche/solcInputs/05be5b065453cde7967331fef060caff.json create mode 100644 deployments/rinkeby/solcInputs/05be5b065453cde7967331fef060caff.json diff --git a/deployments/avalanche/FarmLensV2.json b/deployments/avalanche/FarmLensV2.json index 39ba879c..2cb99632 100644 --- a/deployments/avalanche/FarmLensV2.json +++ b/deployments/avalanche/FarmLensV2.json @@ -1,5 +1,5 @@ { - "address": "0x7F28105B23B32d073eD78A072f3b2e3904f5c4ea", + "address": "0xF16d25Eba0D8E51cEAF480141bAf577aE55bfdd2", "abi": [ { "inputs": [ @@ -371,27 +371,42 @@ }, { "internalType": "uint256", - "name": "userLp", + "name": "baseApr", "type": "uint256" }, { "internalType": "uint256", - "name": "userPendingJoe", + "name": "averageBoostedApr", "type": "uint256" }, { "internalType": "uint256", - "name": "baseAPR", + "name": "veJoeShareBp", "type": "uint256" }, { "internalType": "uint256", - "name": "boostedAPR", + "name": "joePriceUsd", "type": "uint256" }, { "internalType": "uint256", - "name": "boostFactor", + "name": "userLp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "userPendingJoe", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "userBoostedApr", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "userFactorShare", "type": "uint256" } ], @@ -510,27 +525,42 @@ }, { "internalType": "uint256", - "name": "userLp", + "name": "baseApr", "type": "uint256" }, { "internalType": "uint256", - "name": "userPendingJoe", + "name": "averageBoostedApr", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "veJoeShareBp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "joePriceUsd", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "userLp", "type": "uint256" }, { "internalType": "uint256", - "name": "baseAPR", + "name": "userPendingJoe", "type": "uint256" }, { "internalType": "uint256", - "name": "boostedAPR", + "name": "userBoostedApr", "type": "uint256" }, { "internalType": "uint256", - "name": "boostFactor", + "name": "userFactorShare", "type": "uint256" } ], @@ -750,19 +780,19 @@ "type": "function" } ], - "transactionHash": "0xc6d98aa2fbc3d0178b0c54f7e426ffdd0dc674459db0975dfd97f73916dbcc36", + "transactionHash": "0x679bfa751e12bb2e6788f56e9f29bd19209c85c650ffa0fa0fe7e06b7418e963", "receipt": { "to": null, "from": "0x2bC66ec6fEF31e670cc9196c6922CEbd3D96aDad", - "contractAddress": "0x7F28105B23B32d073eD78A072f3b2e3904f5c4ea", + "contractAddress": "0xF16d25Eba0D8E51cEAF480141bAf577aE55bfdd2", "transactionIndex": 0, - "gasUsed": "2676096", + "gasUsed": "2747854", "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "blockHash": "0x52a2bd908941d027259f92ce7afcc416481cc2815abf5c74452a18d9c9e8235a", - "transactionHash": "0xc6d98aa2fbc3d0178b0c54f7e426ffdd0dc674459db0975dfd97f73916dbcc36", + "blockHash": "0x2724e1a2d1573d54b4dcae54ec3748f9a4afd72d1246f38297db5d8f842f3d71", + "transactionHash": "0x679bfa751e12bb2e6788f56e9f29bd19209c85c650ffa0fa0fe7e06b7418e963", "logs": [], - "blockNumber": 12520286, - "cumulativeGasUsed": "2676096", + "blockNumber": 12571840, + "cumulativeGasUsed": "2747854", "status": 1, "byzantium": true }, @@ -777,11 +807,11 @@ "0x188bED1968b795d5c9022F6a0bb5931Ac4c18F00", "0x4483f0b6e2F5486D06958C20f8C39A7aBe87bf8F" ], - "numDeployments": 1, - "solcInputHash": "8e2f9a48c0098ed6f143dc231263c002", - "metadata": "{\"compiler\":{\"version\":\"0.6.12+commit.27d51765\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_joe\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"_wavax\",\"type\":\"address\"},{\"internalType\":\"contract IJoePair\",\"name\":\"_wavaxUsdte\",\"type\":\"address\"},{\"internalType\":\"contract IJoePair\",\"name\":\"_wavaxUsdce\",\"type\":\"address\"},{\"internalType\":\"contract IJoePair\",\"name\":\"_wavaxUsdc\",\"type\":\"address\"},{\"internalType\":\"contract IJoeFactory\",\"name\":\"_joeFactory\",\"type\":\"address\"},{\"internalType\":\"contract IMasterChef\",\"name\":\"_chefv2\",\"type\":\"address\"},{\"internalType\":\"contract IMasterChef\",\"name\":\"_chefv3\",\"type\":\"address\"},{\"internalType\":\"contract IBoostedMasterchef\",\"name\":\"_bmcj\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"bmcj\",\"outputs\":[{\"internalType\":\"contract IBoostedMasterchef\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"chefv2\",\"outputs\":[{\"internalType\":\"contract IMasterChef\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"chefv3\",\"outputs\":[{\"internalType\":\"contract IMasterChef\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPidsV2\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPidsV3\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPidsBMCJ\",\"type\":\"uint256[]\"},{\"internalType\":\"address\",\"name\":\"user\",\"type\":\"address\"}],\"name\":\"getAllFarmData\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"avaxPriceUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePriceUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAllocChefV2\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAllocChefV3\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAllocBMCJ\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePerSecChefV2\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePerSecChefV3\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePerSecBMCJ\",\"type\":\"uint256\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfo[]\",\"name\":\"farmInfosV2\",\"type\":\"tuple[]\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfo[]\",\"name\":\"farmInfosV3\",\"type\":\"tuple[]\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userLp\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userPendingJoe\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"baseAPR\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"boostedAPR\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"boostFactor\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfoBMCJ[]\",\"name\":\"farmInfosBMCJ\",\"type\":\"tuple[]\"}],\"internalType\":\"struct FarmLensV2.AllFarmData\",\"name\":\"\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getAvaxPrice\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"contract IBoostedMasterchef\",\"name\":\"chef\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"user\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPids\",\"type\":\"uint256[]\"}],\"name\":\"getBMCJFarmInfos\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userLp\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userPendingJoe\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"baseAPR\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"boostedAPR\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"boostFactor\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfoBMCJ[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"}],\"name\":\"getDerivedAvaxPriceOfToken\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"contract IMasterChef\",\"name\":\"chef\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPids\",\"type\":\"uint256[]\"}],\"name\":\"getMCFarmInfos\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfo[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"}],\"name\":\"getTokenPrice\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"joe\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"joeFactory\",\"outputs\":[{\"internalType\":\"contract IJoeFactory\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavax\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavaxUsdc\",\"outputs\":[{\"internalType\":\"contract IJoePair\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavaxUsdce\",\"outputs\":[{\"internalType\":\"contract IJoePair\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavaxUsdte\",\"outputs\":[{\"internalType\":\"contract IJoePair\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"getAllFarmData(uint256[],uint256[],uint256[],address)\":{\"params\":{\"user\":\"The address of the user, if address(0), returns global info\",\"whitelistedPidsBMCJ\":\"Array of all ids of pools that are whitelisted in BMCJ\",\"whitelistedPidsV2\":\"Array of all ids of pools that are whitelisted in chefV2\",\"whitelistedPidsV3\":\"Array of all ids of pools that are whitelisted in chefV3\"},\"returns\":{\"_0\":\"AllFarmData The information of all the whitelisted farms of MCV2, MCV3 and BMCJ\"}},\"getAvaxPrice()\":{\"returns\":{\"_0\":\"uint256 the avax price, scaled to 18 decimals\"}},\"getBMCJFarmInfos(address,address,uint256[])\":{\"params\":{\"chef\":\"The address of the MasterChef\",\"user\":\"The address of the user, if address(0), returns global info\",\"whitelistedPids\":\"Array of all ids of pools that are whitelisted and valid to have their farm data returned\"},\"returns\":{\"_0\":\"FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\"}},\"getDerivedAvaxPriceOfToken(address)\":{\"params\":{\"token\":\"The address of the token\"},\"returns\":{\"_0\":\"uint256 the token derived price, scaled to 18 decimals\"}},\"getMCFarmInfos(address,uint256[])\":{\"params\":{\"chef\":\"The address of the MasterChef\",\"whitelistedPids\":\"Array of all ids of pools that are whitelisted and valid to have their farm data returned\"},\"returns\":{\"_0\":\"FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\"}},\"getTokenPrice(address)\":{\"params\":{\"token\":\"The address of the token\"},\"returns\":{\"_0\":\"uint256 the Usd price of token, scaled to 18 decimals\"}}},\"stateVariables\":{\"SEC_PER_YEAR\":{\"details\":\"365 * 86400, hard coding it for gas optimisation\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"getAllFarmData(uint256[],uint256[],uint256[],address)\":{\"notice\":\"Get all data needed for useFarms hook.\"},\"getAvaxPrice()\":{\"notice\":\"Returns the price of avax in Usd\"},\"getBMCJFarmInfos(address,address,uint256[])\":{\"notice\":\"Returns the farm pairs data for BoostedMasterChefJoe\"},\"getDerivedAvaxPriceOfToken(address)\":{\"notice\":\"Returns the derived price of token, it needs to be paired with wavax\"},\"getMCFarmInfos(address,uint256[])\":{\"notice\":\"Returns the farm pairs data for MCV2 and MCV3\"},\"getTokenPrice(address)\":{\"notice\":\"Returns the Usd price of token, it needs to be paired with wavax\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"contracts/traderjoe/FarmLensV2.sol\":\"FarmLensV2\"},\"evmVersion\":\"istanbul\",\"libraries\":{\"__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"contracts/interfaces/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\n\\ninterface IERC20 {\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address account) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 amount) external returns (bool);\\n\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n\\n // EIP 2612\\n function permit(\\n address owner,\\n address spender,\\n uint256 value,\\n uint256 deadline,\\n uint8 v,\\n bytes32 r,\\n bytes32 s\\n ) external;\\n}\\n\",\"keccak256\":\"0xa3fb82796e80f566a5c47f9a1f2ade7de7f390dfdc06bea5375112b9f9314f40\",\"license\":\"MIT\"},\"contracts/libraries/SafeERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\n\\nimport \\\"../interfaces/IERC20.sol\\\";\\n\\nlibrary SafeERC20 {\\n function safeSymbol(IERC20 token) internal view returns (string memory) {\\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x95d89b41));\\n return success && data.length > 0 ? abi.decode(data, (string)) : \\\"???\\\";\\n }\\n\\n function safeName(IERC20 token) internal view returns (string memory) {\\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x06fdde03));\\n return success && data.length > 0 ? abi.decode(data, (string)) : \\\"???\\\";\\n }\\n\\n function safeDecimals(IERC20 token) internal view returns (uint8) {\\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x313ce567));\\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\\n }\\n\\n function safeTransfer(\\n IERC20 token,\\n address to,\\n uint256 amount\\n ) internal {\\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(0xa9059cbb, to, amount));\\n require(success && (data.length == 0 || abi.decode(data, (bool))), \\\"SafeERC20: Transfer failed\\\");\\n }\\n\\n function safeTransferFrom(\\n IERC20 token,\\n address from,\\n uint256 amount\\n ) internal {\\n (bool success, bytes memory data) = address(token).call(\\n abi.encodeWithSelector(0x23b872dd, from, address(this), amount)\\n );\\n require(success && (data.length == 0 || abi.decode(data, (bool))), \\\"SafeERC20: TransferFrom failed\\\");\\n }\\n}\\n\",\"keccak256\":\"0xdd77ee6d503b5396208d64e811ee89ca55389c62071003cc223f4ea0029c10ac\",\"license\":\"MIT\"},\"contracts/libraries/SafeMath.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\n\\n// a library for performing overflow-safe math, updated with awesomeness from of DappHub (https://github.com/dapphub/ds-math)\\nlibrary SafeMath {\\n function add(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require((c = a + b) >= b, \\\"SafeMath: Add Overflow\\\");\\n }\\n\\n function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require((c = a - b) <= a, \\\"SafeMath: Underflow\\\");\\n }\\n\\n function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require(b == 0 || (c = a * b) / b == a, \\\"SafeMath: Mul Overflow\\\");\\n }\\n\\n function div(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require(b > 0, \\\"SafeMath: Div by Zero\\\");\\n c = a / b;\\n }\\n\\n function to128(uint256 a) internal pure returns (uint128 c) {\\n require(a <= uint128(-1), \\\"SafeMath: uint128 Overflow\\\");\\n c = uint128(a);\\n }\\n}\\n\\nlibrary SafeMath128 {\\n function add(uint128 a, uint128 b) internal pure returns (uint128 c) {\\n require((c = a + b) >= b, \\\"SafeMath: Add Overflow\\\");\\n }\\n\\n function sub(uint128 a, uint128 b) internal pure returns (uint128 c) {\\n require((c = a - b) <= a, \\\"SafeMath: Underflow\\\");\\n }\\n}\\n\",\"keccak256\":\"0x8b8dcb649a07667a9a97c050a374a82389e7a19254abaebedf399c00619042a8\",\"license\":\"MIT\"},\"contracts/traderjoe/FarmLensV2.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\npragma experimental ABIEncoderV2;\\nimport \\\"../libraries/SafeMath.sol\\\";\\nimport \\\"../libraries/SafeERC20.sol\\\";\\n\\nimport \\\"./interfaces/IERC20.sol\\\";\\nimport \\\"./interfaces/IJoeERC20.sol\\\";\\nimport \\\"./interfaces/IJoePair.sol\\\";\\nimport \\\"./interfaces/IJoeFactory.sol\\\";\\n\\ninterface IMasterChef {\\n struct PoolInfo {\\n IJoeERC20 lpToken; // Address of LP token contract.\\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\\n }\\n\\n function poolLength() external view returns (uint256);\\n\\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\\n\\n function totalAllocPoint() external view returns (uint256);\\n\\n function joePerSec() external view returns (uint256);\\n}\\n\\ninterface IBoostedMasterchef {\\n struct UserInfo {\\n uint256 amount;\\n uint256 rewardDebt;\\n uint256 factor;\\n }\\n\\n struct PoolInfo {\\n IERC20 lpToken;\\n uint96 allocPoint;\\n uint256 accJoePerShare;\\n uint256 accJoePerFactorPerShare;\\n uint64 lastRewardTimestamp;\\n address rewarder;\\n uint32 veJoeShareBp;\\n uint256 totalFactor;\\n uint256 totalLpSupply;\\n }\\n\\n function userInfo(uint256 _pid, address user) external view returns (UserInfo memory);\\n \\n function pendingTokens(uint256 _pid, address user) external view returns (uint256, address, string memory, uint256);\\n\\n function poolLength() external view returns (uint256);\\n\\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\\n\\n function totalAllocPoint() external view returns (uint256);\\n\\n function joePerSec() external view returns (uint256);\\n}\\n\\ncontract FarmLensV2 {\\n using SafeMath for uint256;\\n using SafeERC20 for IERC20;\\n\\n struct FarmInfo {\\n uint256 id;\\n uint256 allocPoint;\\n address lpAddress;\\n address token0Address;\\n address token1Address;\\n string token0Symbol;\\n string token1Symbol;\\n uint256 reserveUsd;\\n uint256 totalSupplyScaled;\\n address chefAddress;\\n uint256 chefBalanceScaled;\\n uint256 chefTotalAlloc;\\n uint256 chefJoePerSec;\\n }\\n\\n struct FarmInfoBMCJ {\\n uint256 id;\\n uint256 allocPoint;\\n address lpAddress;\\n address token0Address;\\n address token1Address;\\n string token0Symbol;\\n string token1Symbol;\\n uint256 reserveUsd;\\n uint256 totalSupplyScaled;\\n address chefAddress;\\n uint256 chefBalanceScaled;\\n uint256 chefTotalAlloc;\\n uint256 chefJoePerSec;\\n uint256 userLp;\\n uint256 userPendingJoe;\\n uint256 baseAPR;\\n uint256 boostedAPR;\\n uint256 boostFactor;\\n }\\n\\n struct AllFarmData {\\n uint256 avaxPriceUsd;\\n uint256 joePriceUsd;\\n uint256 totalAllocChefV2;\\n uint256 totalAllocChefV3;\\n uint256 totalAllocBMCJ;\\n uint256 joePerSecChefV2;\\n uint256 joePerSecChefV3;\\n uint256 joePerSecBMCJ;\\n FarmInfo[] farmInfosV2;\\n FarmInfo[] farmInfosV3;\\n FarmInfoBMCJ[] farmInfosBMCJ;\\n }\\n\\n struct GlobalInfo {\\n address chef;\\n uint256 totalAlloc;\\n uint256 joePerSec;\\n }\\n\\n /// @dev 365 * 86400, hard coding it for gas optimisation\\n uint256 private constant SEC_PER_YEAR = 31536000;\\n uint256 private constant BP_PRECISION = 10_000;\\n uint256 private constant PRECISION = 1e18;\\n\\n address public immutable joe; // 0x6e84a6216eA6dACC71eE8E6b0a5B7322EEbC0fDd;\\n address public immutable wavax; // 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7;\\n IJoePair public immutable wavaxUsdte; // 0xeD8CBD9F0cE3C6986b22002F03c6475CEb7a6256\\n IJoePair public immutable wavaxUsdce; // 0xA389f9430876455C36478DeEa9769B7Ca4E3DDB1\\n IJoePair public immutable wavaxUsdc; // 0xf4003f4efbe8691b60249e6afbd307abe7758adb\\n IJoeFactory public immutable joeFactory; // 0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10\\n IMasterChef public immutable chefv2; // 0xd6a4F121CA35509aF06A0Be99093d08462f53052\\n IMasterChef public immutable chefv3; // 0x188bED1968b795d5c9022F6a0bb5931Ac4c18F00\\n IBoostedMasterchef public immutable bmcj; // Not deployed yet\\n bool private immutable isWavaxToken1InWavaxUsdte;\\n bool private immutable isWavaxToken1InWavaxUsdce;\\n bool private immutable isWavaxToken1InWavaxUsdc;\\n\\n constructor(\\n address _joe,\\n address _wavax,\\n IJoePair _wavaxUsdte,\\n IJoePair _wavaxUsdce,\\n IJoePair _wavaxUsdc,\\n IJoeFactory _joeFactory,\\n IMasterChef _chefv2,\\n IMasterChef _chefv3,\\n IBoostedMasterchef _bmcj\\n ) public {\\n joe = _joe;\\n wavax = _wavax;\\n wavaxUsdte = _wavaxUsdte;\\n wavaxUsdce = _wavaxUsdce;\\n wavaxUsdc = _wavaxUsdc;\\n joeFactory = _joeFactory;\\n chefv2 = _chefv2;\\n chefv3 = _chefv3;\\n bmcj = _bmcj;\\n\\n isWavaxToken1InWavaxUsdte = _wavaxUsdte.token1() == _wavax;\\n isWavaxToken1InWavaxUsdce = _wavaxUsdce.token1() == _wavax;\\n isWavaxToken1InWavaxUsdc = _wavaxUsdc.token1() == _wavax;\\n }\\n\\n /// @notice Returns the price of avax in Usd\\n /// @return uint256 the avax price, scaled to 18 decimals\\n function getAvaxPrice() external view returns (uint256) {\\n return _getAvaxPrice();\\n }\\n\\n /// @notice Returns the derived price of token, it needs to be paired with wavax\\n /// @param token The address of the token\\n /// @return uint256 the token derived price, scaled to 18 decimals\\n function getDerivedAvaxPriceOfToken(address token) external view returns (uint256) {\\n return _getDerivedAvaxPriceOfToken(token);\\n }\\n\\n /// @notice Returns the Usd price of token, it needs to be paired with wavax\\n /// @param token The address of the token\\n /// @return uint256 the Usd price of token, scaled to 18 decimals\\n function getTokenPrice(address token) external view returns (uint256) {\\n return _getDerivedAvaxPriceOfToken(token).mul(_getAvaxPrice()) / 1e18;\\n }\\n\\n /// @notice Returns the farm pairs data for MCV2 and MCV3\\n /// @param chef The address of the MasterChef\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\\n function getMCFarmInfos(IMasterChef chef, uint256[] calldata whitelistedPids)\\n external\\n view\\n returns (FarmInfo[] memory)\\n {\\n require(chef == chefv2 || chef == chefv3, \\\"FarmLensV2: only for MCV2 and MCV3\\\");\\n\\n uint256 avaxPrice = _getAvaxPrice();\\n return _getMCFarmInfos(chef, avaxPrice, whitelistedPids);\\n }\\n\\n /// @notice Returns the farm pairs data for BoostedMasterChefJoe\\n /// @param chef The address of the MasterChef\\n /// @param user The address of the user, if address(0), returns global info\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\\n function getBMCJFarmInfos(\\n IBoostedMasterchef chef,\\n address user,\\n uint256[] calldata whitelistedPids\\n ) external view returns (FarmInfoBMCJ[] memory) {\\n require(chef == bmcj, \\\"FarmLensV2: Only for BMCJ\\\");\\n\\n uint256 avaxPrice = _getAvaxPrice();\\n uint256 joePrice = _getDerivedAvaxPriceOfToken(joe).mul(avaxPrice) / PRECISION;\\n return _getBMCJFarmInfos(avaxPrice, joePrice, user, whitelistedPids);\\n }\\n\\n /// @notice Get all data needed for useFarms hook.\\n /// @param whitelistedPidsV2 Array of all ids of pools that are whitelisted in chefV2\\n /// @param whitelistedPidsV3 Array of all ids of pools that are whitelisted in chefV3\\n /// @param whitelistedPidsBMCJ Array of all ids of pools that are whitelisted in BMCJ\\n /// @param user The address of the user, if address(0), returns global info\\n /// @return AllFarmData The information of all the whitelisted farms of MCV2, MCV3 and BMCJ\\n function getAllFarmData(\\n uint256[] calldata whitelistedPidsV2,\\n uint256[] calldata whitelistedPidsV3,\\n uint256[] calldata whitelistedPidsBMCJ,\\n address user\\n ) external view returns (AllFarmData memory) {\\n AllFarmData memory allFarmData;\\n\\n uint256 avaxPrice = _getAvaxPrice();\\n uint256 joePrice = _getDerivedAvaxPriceOfToken(joe).mul(avaxPrice) / PRECISION;\\n\\n allFarmData.avaxPriceUsd = avaxPrice;\\n allFarmData.joePriceUsd = joePrice;\\n\\n allFarmData.totalAllocChefV2 = chefv2.totalAllocPoint();\\n allFarmData.joePerSecChefV2 = chefv2.joePerSec();\\n\\n allFarmData.totalAllocChefV3 = chefv3.totalAllocPoint();\\n allFarmData.joePerSecChefV3 = chefv3.joePerSec();\\n\\n allFarmData.totalAllocBMCJ = bmcj.totalAllocPoint();\\n allFarmData.joePerSecBMCJ = bmcj.joePerSec();\\n\\n allFarmData.farmInfosV2 = _getMCFarmInfos(chefv2, avaxPrice, whitelistedPidsV2);\\n allFarmData.farmInfosV3 = _getMCFarmInfos(chefv3, avaxPrice, whitelistedPidsV3);\\n allFarmData.farmInfosBMCJ = _getBMCJFarmInfos(avaxPrice, joePrice, user, whitelistedPidsBMCJ);\\n\\n return allFarmData;\\n }\\n\\n /// @notice Returns the price of avax in Usd internally\\n /// @return uint256 the avax price, scaled to 18 decimals\\n function _getAvaxPrice() private view returns (uint256) {\\n return\\n _getDerivedTokenPriceOfPair(wavaxUsdte, isWavaxToken1InWavaxUsdte)\\n .add(_getDerivedTokenPriceOfPair(wavaxUsdce, isWavaxToken1InWavaxUsdce))\\n .add(_getDerivedTokenPriceOfPair(wavaxUsdc, isWavaxToken1InWavaxUsdc)) / 3;\\n }\\n\\n /// @notice Returns the derived price of token in the other token\\n /// @param pair The address of the pair\\n /// @param derivedtoken0 If price should be derived from token0 if true, or token1 if false\\n /// @return uint256 the derived price, scaled to 18 decimals\\n function _getDerivedTokenPriceOfPair(IJoePair pair, bool derivedtoken0) private view returns (uint256) {\\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\\n uint256 decimals0 = IERC20(pair.token0()).safeDecimals();\\n uint256 decimals1 = IERC20(pair.token1()).safeDecimals();\\n\\n if (derivedtoken0) {\\n return _scaleTo(reserve0, decimals1.add(18).sub(decimals0)).div(reserve1);\\n } else {\\n return _scaleTo(reserve1, decimals0.add(18).sub(decimals1)).div(reserve0);\\n }\\n }\\n\\n /// @notice Returns the derived price of token, it needs to be paired with wavax\\n /// @param token The address of the token\\n /// @return uint256 the token derived price, scaled to 18 decimals\\n function _getDerivedAvaxPriceOfToken(address token) private view returns (uint256) {\\n if (token == wavax) {\\n return PRECISION;\\n }\\n IJoePair pair = IJoePair(joeFactory.getPair(token, wavax));\\n if (address(pair) == address(0)) {\\n return 0;\\n }\\n // instead of testing wavax == pair.token0(), we do the opposite to save gas\\n return _getDerivedTokenPriceOfPair(pair, token == pair.token1());\\n }\\n\\n /// @notice Returns the amount scaled to decimals\\n /// @param amount The amount\\n /// @param decimals The decimals to scale `amount`\\n /// @return uint256 The amount scaled to decimals\\n function _scaleTo(uint256 amount, uint256 decimals) private pure returns (uint256) {\\n if (decimals == 0) return amount;\\n return amount.mul(10**decimals);\\n }\\n\\n /// @notice Returns the derived avax liquidity, at least one of the token needs to be paired with wavax\\n /// @param pair The address of the pair\\n /// @return uint256 the derived price of pair's liquidity, scaled to 18 decimals\\n function _getDerivedAvaxLiquidityOfPair(IJoePair pair) private view returns (uint256) {\\n address _wavax = wavax;\\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\\n IERC20 token0 = IERC20(pair.token0());\\n IERC20 token1 = IERC20(pair.token1());\\n uint256 decimals0 = token0.safeDecimals();\\n uint256 decimals1 = token1.safeDecimals();\\n\\n reserve0 = _scaleTo(reserve0, uint256(18).sub(decimals0));\\n reserve1 = _scaleTo(reserve1, uint256(18).sub(decimals1));\\n\\n uint256 token0DerivedAvaxPrice;\\n uint256 token1DerivedAvaxPrice;\\n if (address(token0) == _wavax) {\\n token0DerivedAvaxPrice = PRECISION;\\n token1DerivedAvaxPrice = _getDerivedTokenPriceOfPair(pair, true);\\n } else if (address(token1) == _wavax) {\\n token0DerivedAvaxPrice = _getDerivedTokenPriceOfPair(pair, false);\\n token1DerivedAvaxPrice = PRECISION;\\n } else {\\n token0DerivedAvaxPrice = _getDerivedAvaxPriceOfToken(address(token0));\\n token1DerivedAvaxPrice = _getDerivedAvaxPriceOfToken(address(token1));\\n // If one token isn't paired with wavax, then we hope that the second one is.\\n // E.g, TOKEN/UsdC, token might not be paired with wavax, but UsdC is.\\n // If both aren't paired with wavax, return 0\\n if (token0DerivedAvaxPrice == 0) return reserve1.mul(token1DerivedAvaxPrice).mul(2) / PRECISION;\\n if (token1DerivedAvaxPrice == 0) return reserve0.mul(token0DerivedAvaxPrice).mul(2) / PRECISION;\\n }\\n return reserve0.mul(token0DerivedAvaxPrice).add(reserve1.mul(token1DerivedAvaxPrice)) / PRECISION;\\n }\\n\\n /// @notice Private function to return the farm pairs data for a given MasterChef (V2 or V3)\\n /// @param chef The address of the MasterChef\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\\n function _getMCFarmInfos(\\n IMasterChef chef,\\n uint256 avaxPrice,\\n uint256[] calldata whitelistedPids\\n ) private view returns (FarmInfo[] memory) {\\n uint256 whitelistLength = whitelistedPids.length;\\n FarmInfo[] memory farmInfos = new FarmInfo[](whitelistLength);\\n\\n uint256 chefTotalAlloc = chef.totalAllocPoint();\\n uint256 chefJoePerSec = chef.joePerSec();\\n\\n for (uint256 i; i < whitelistLength; i++) {\\n uint256 pid = whitelistedPids[i];\\n IMasterChef.PoolInfo memory pool = chef.poolInfo(pid);\\n\\n farmInfos[i] = _getMCFarmInfo(\\n chef,\\n avaxPrice,\\n pid,\\n IJoePair(address(pool.lpToken)),\\n pool.allocPoint,\\n chefTotalAlloc,\\n chefJoePerSec\\n );\\n }\\n\\n return farmInfos;\\n }\\n\\n /// @notice Helper function to return the farm info of a given pool\\n /// @param chef The address of the MasterChef\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param pid The pid of the pool\\n /// @param lpToken The lpToken of the pool\\n /// @param allocPoint The allocPoint of the pool\\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\\n function _getMCFarmInfo(\\n IMasterChef chef,\\n uint256 avaxPrice,\\n uint256 pid,\\n IJoePair lpToken,\\n uint256 allocPoint,\\n uint256 totalAllocPoint,\\n uint256 chefJoePerSec\\n ) private view returns (FarmInfo memory) {\\n uint256 decimals = lpToken.decimals();\\n uint256 totalSupplyScaled = _scaleTo(lpToken.totalSupply(), 18 - decimals);\\n uint256 chefBalanceScaled = _scaleTo(lpToken.balanceOf(address(chef)), 18 - decimals);\\n uint256 reserveUsd = _getDerivedAvaxLiquidityOfPair(lpToken).mul(avaxPrice) / PRECISION;\\n IERC20 token0 = IERC20(lpToken.token0());\\n IERC20 token1 = IERC20(lpToken.token1());\\n\\n return\\n FarmInfo({\\n id: pid,\\n allocPoint: allocPoint,\\n lpAddress: address(lpToken),\\n token0Address: address(token0),\\n token1Address: address(token1),\\n token0Symbol: token0.safeSymbol(),\\n token1Symbol: token1.safeSymbol(),\\n reserveUsd: reserveUsd,\\n totalSupplyScaled: totalSupplyScaled,\\n chefBalanceScaled: chefBalanceScaled,\\n chefAddress: address(chef),\\n chefTotalAlloc: totalAllocPoint,\\n chefJoePerSec: chefJoePerSec\\n });\\n }\\n\\n /// @notice Private function to return the farm pairs data for boostedMasterChef\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param joePrice The joe price as a parameter to save gas\\n /// @param user The address of the user, if address(0), returns global info\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\\n function _getBMCJFarmInfos(\\n uint256 avaxPrice,\\n uint256 joePrice,\\n address user,\\n uint256[] calldata whitelistedPids\\n ) private view returns (FarmInfoBMCJ[] memory) {\\n GlobalInfo memory globalInfo = GlobalInfo(address(bmcj), bmcj.totalAllocPoint(), bmcj.joePerSec());\\n\\n uint256 whitelistLength = whitelistedPids.length;\\n FarmInfoBMCJ[] memory farmInfos = new FarmInfoBMCJ[](whitelistLength);\\n\\n for (uint256 i; i < whitelistLength; i++) {\\n uint256 pid = whitelistedPids[i];\\n IBoostedMasterchef.PoolInfo memory pool = IBoostedMasterchef(globalInfo.chef).poolInfo(pid);\\n IBoostedMasterchef.UserInfo memory userInfo;\\n userInfo = IBoostedMasterchef(globalInfo.chef).userInfo(pid, user);\\n\\n farmInfos[i].id = pid;\\n farmInfos[i].chefAddress = globalInfo.chef;\\n farmInfos[i].chefTotalAlloc = globalInfo.totalAlloc;\\n farmInfos[i].chefJoePerSec = globalInfo.joePerSec;\\n _getBMCJFarmInfo(\\n avaxPrice,\\n globalInfo.joePerSec.mul(joePrice) / PRECISION,\\n user,\\n farmInfos[i],\\n pool,\\n userInfo\\n );\\n }\\n\\n return farmInfos;\\n }\\n\\n /// @notice Helper function to return the farm info of a given pool of BMCJ\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param UsdPerSec The Usd per sec emitted to BMCJ\\n /// @param userAddress The address of the user\\n /// @param farmInfo The farmInfo of that pool\\n /// @param user The user information\\n function _getBMCJFarmInfo(\\n uint256 avaxPrice,\\n uint256 UsdPerSec,\\n address userAddress,\\n FarmInfoBMCJ memory farmInfo,\\n IBoostedMasterchef.PoolInfo memory pool,\\n IBoostedMasterchef.UserInfo memory user\\n ) private view {\\n {\\n IJoePair lpToken = IJoePair(address(pool.lpToken));\\n IERC20 token0 = IERC20(lpToken.token0());\\n IERC20 token1 = IERC20(lpToken.token1());\\n\\n farmInfo.allocPoint = pool.allocPoint;\\n farmInfo.lpAddress = address(lpToken);\\n farmInfo.token0Address = address(token0);\\n farmInfo.token1Address = address(token1);\\n farmInfo.token0Symbol = token0.safeSymbol();\\n farmInfo.token1Symbol = token1.safeSymbol();\\n farmInfo.reserveUsd = _getDerivedAvaxLiquidityOfPair(lpToken).mul(avaxPrice) / PRECISION;\\n // LP is in 18 decimals, so it's already scaled for JLP\\n farmInfo.totalSupplyScaled = lpToken.totalSupply();\\n farmInfo.chefBalanceScaled = pool.totalLpSupply;\\n farmInfo.userLp = user.amount;\\n (farmInfo.userPendingJoe, , , ) = bmcj.pendingTokens(farmInfo.id, userAddress);\\n if (pool.veJoeShareBp == BP_PRECISION) {\\n farmInfo.boostFactor = ~uint256(0);\\n } else {\\n // can't over or underflow, so normal math is fine\\n farmInfo.boostFactor =\\n (pool.veJoeShareBp * BP_PRECISION) /\\n (BP_PRECISION - pool.veJoeShareBp) +\\n BP_PRECISION;\\n }\\n }\\n\\n if (pool.totalLpSupply != 0 && farmInfo.totalSupplyScaled != 0 && farmInfo.chefTotalAlloc != 0 && farmInfo.reserveUsd != 0) {\\n uint256 poolUsdPerYear = UsdPerSec.mul(pool.allocPoint).mul(SEC_PER_YEAR) / farmInfo.chefTotalAlloc;\\n\\n uint256 poolReserveUsd = farmInfo.reserveUsd.mul(farmInfo.chefBalanceScaled) / farmInfo.totalSupplyScaled;\\n\\n if (poolReserveUsd == 0) return;\\n\\n farmInfo.baseAPR =\\n poolUsdPerYear.mul(BP_PRECISION - pool.veJoeShareBp).mul(PRECISION) /\\n poolReserveUsd /\\n BP_PRECISION;\\n\\n if (pool.totalFactor != 0 && user.amount != 0) {\\n uint256 userLpUsd = user.amount.mul(farmInfo.reserveUsd) / pool.totalLpSupply;\\n\\n farmInfo.boostedAPR =\\n poolUsdPerYear.mul(pool.veJoeShareBp).mul(user.factor).div(pool.totalFactor).mul(PRECISION) /\\n userLpUsd /\\n BP_PRECISION;\\n } else {\\n farmInfo.boostedAPR = \\n poolUsdPerYear.mul(pool.veJoeShareBp).mul(PRECISION) /\\n poolReserveUsd /\\n BP_PRECISION;\\n }\\n }\\n }\\n}\\n\",\"keccak256\":\"0x0c4e878889c4d541ade9b15067311f8ad879964ba07a9fc076e4a36c6c27d16d\",\"license\":\"MIT\"},\"contracts/traderjoe/interfaces/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IERC20Joe {\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n function name() external view returns (string memory);\\n\\n function symbol() external view returns (string memory);\\n\\n function decimals() external view returns (uint8);\\n\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address owner) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n function transferFrom(\\n address from,\\n address to,\\n uint256 value\\n ) external returns (bool);\\n}\\n\",\"keccak256\":\"0xd5d59683ac059dc8c7a528d9243a0434d727bcddd4e477d4b26d50ae4f78ea05\",\"license\":\"GPL-3.0\"},\"contracts/traderjoe/interfaces/IJoeERC20.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IJoeERC20 {\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n function name() external pure returns (string memory);\\n\\n function symbol() external pure returns (string memory);\\n\\n function decimals() external pure returns (uint8);\\n\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address owner) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n function transferFrom(\\n address from,\\n address to,\\n uint256 value\\n ) external returns (bool);\\n\\n function DOMAIN_SEPARATOR() external view returns (bytes32);\\n\\n function PERMIT_TYPEHASH() external pure returns (bytes32);\\n\\n function nonces(address owner) external view returns (uint256);\\n\\n function permit(\\n address owner,\\n address spender,\\n uint256 value,\\n uint256 deadline,\\n uint8 v,\\n bytes32 r,\\n bytes32 s\\n ) external;\\n}\\n\",\"keccak256\":\"0x0f9b1de8137e61afcf2c09fde27dc657da98b7c19c1811fd205ffbe877490d36\",\"license\":\"GPL-3.0\"},\"contracts/traderjoe/interfaces/IJoeFactory.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IJoeFactory {\\n event PairCreated(address indexed token0, address indexed token1, address pair, uint256);\\n\\n function feeTo() external view returns (address);\\n\\n function feeToSetter() external view returns (address);\\n\\n function migrator() external view returns (address);\\n\\n function getPair(address tokenA, address tokenB) external view returns (address pair);\\n\\n function allPairs(uint256) external view returns (address pair);\\n\\n function allPairsLength() external view returns (uint256);\\n\\n function createPair(address tokenA, address tokenB) external returns (address pair);\\n\\n function setFeeTo(address) external;\\n\\n function setFeeToSetter(address) external;\\n\\n function setMigrator(address) external;\\n}\\n\",\"keccak256\":\"0x0e31007ead341ae106c1ca874629b527886427f7f47641d96e0d172720f2c3ca\",\"license\":\"GPL-3.0\"},\"contracts/traderjoe/interfaces/IJoePair.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IJoePair {\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n function name() external pure returns (string memory);\\n\\n function symbol() external pure returns (string memory);\\n\\n function decimals() external pure returns (uint8);\\n\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address owner) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n function transferFrom(\\n address from,\\n address to,\\n uint256 value\\n ) external returns (bool);\\n\\n function DOMAIN_SEPARATOR() external view returns (bytes32);\\n\\n function PERMIT_TYPEHASH() external pure returns (bytes32);\\n\\n function nonces(address owner) external view returns (uint256);\\n\\n function permit(\\n address owner,\\n address spender,\\n uint256 value,\\n uint256 deadline,\\n uint8 v,\\n bytes32 r,\\n bytes32 s\\n ) external;\\n\\n event Mint(address indexed sender, uint256 amount0, uint256 amount1);\\n event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);\\n event Swap(\\n address indexed sender,\\n uint256 amount0In,\\n uint256 amount1In,\\n uint256 amount0Out,\\n uint256 amount1Out,\\n address indexed to\\n );\\n event Sync(uint112 reserve0, uint112 reserve1);\\n\\n function MINIMUM_LIQUIDITY() external pure returns (uint256);\\n\\n function factory() external view returns (address);\\n\\n function token0() external view returns (address);\\n\\n function token1() external view returns (address);\\n\\n function getReserves()\\n external\\n view\\n returns (\\n uint112 reserve0,\\n uint112 reserve1,\\n uint32 blockTimestampLast\\n );\\n\\n function price0CumulativeLast() external view returns (uint256);\\n\\n function price1CumulativeLast() external view returns (uint256);\\n\\n function kLast() external view returns (uint256);\\n\\n function mint(address to) external returns (uint256 liquidity);\\n\\n function burn(address to) external returns (uint256 amount0, uint256 amount1);\\n\\n function swap(\\n uint256 amount0Out,\\n uint256 amount1Out,\\n address to,\\n bytes calldata data\\n ) external;\\n\\n function skim(address to) external;\\n\\n function sync() external;\\n\\n function initialize(address, address) external;\\n}\\n\",\"keccak256\":\"0xd4d926f79ca1de45dc3f8a7e8244d62a54522cb1a3f38d881979319363ee1387\",\"license\":\"GPL-3.0\"}},\"version\":1}", - "bytecode": "0x6102006040523480156200001257600080fd5b506040516200339438038062003394833981016040819052620000359162000285565b6001600160601b031960608a811b821660805289811b821660a05288811b821660c05287811b821660e05286811b82166101005285811b82166101205284811b82166101405283811b82166101605282901b16610180526040805163d21220a760e01b815290516001600160a01b038a811692908a169163d21220a791600480820192602092909190829003018186803b158015620000d357600080fd5b505afa158015620000e8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200010e91906200025f565b6001600160a01b03161415156101a081151560f81b81525050876001600160a01b0316866001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156200016b57600080fd5b505afa15801562000180573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620001a691906200025f565b6001600160a01b03161415156101c081151560f81b81525050876001600160a01b0316856001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156200020357600080fd5b505afa15801562000218573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200023e91906200025f565b6001600160a01b03161460f81b6101e0525062000374975050505050505050565b60006020828403121562000271578081fd5b81516200027e816200035b565b9392505050565b60008060008060008060008060006101208a8c031215620002a4578485fd5b8951620002b1816200035b565b60208b0151909950620002c4816200035b565b60408b0151909850620002d7816200035b565b60608b0151909750620002ea816200035b565b60808b0151909650620002fd816200035b565b60a08b015190955062000310816200035b565b60c08b015190945062000323816200035b565b60e08b015190935062000336816200035b565b6101008b01519092506200034a816200035b565b809150509295985092959850929598565b6001600160a01b03811681146200037157600080fd5b50565b60805160601c60a05160601c60c05160601c60e05160601c6101005160601c6101205160601c6101405160601c6101605160601c6101805160601c6101a05160f81c6101c05160f81c6101e05160f81c612efe62000496600039806109b8525080610a05525080610a4f5250806101f5528061053e52806105d852806108635280610ebf5280610eee5280610f8452806119c652508061023d528061040a52806104a452806106a352806107c15250806102e95280610370528061067152806106f452806107865250806107605280610aeb52508061073c528061099752508061091a52806109e45250806107185280610a2e5250806102195280610a8a5280610b1a5280611db652508061028f528061083d52806108d25250612efe6000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c80638a38466e11610097578063cff5dd3311610066578063cff5dd33146101b0578063d02641a0146101b8578063eee5c276146101d8578063f97a496c146101eb576100f5565b80638a38466e146101605780639bbf1deb14610168578063b985a3a014610188578063ce7a198914610190576100f5565b806335541641116100d357806335541641146101285780634e57afe014610148578063685f02e71461015057806387dabe4614610158576100f5565b80630d1dcd9a146100fa578063117be4c2146101185780632c9e2b0514610120575b600080fd5b6101026101f3565b60405161010f9190612b91565b60405180910390f35b610102610217565b61010261023b565b61013b610136366004612517565b61025f565b60405161010f9190612d67565b6101026106f2565b610102610716565b61010261073a565b61010261075e565b61017b610176366004612624565b610782565b60405161010f9190612c1f565b61010261083b565b6101a361019e3660046125c1565b61085f565b60405161010f9190612bbf565b610102610918565b6101cb6101c63660046124df565b61093c565b60405161010f9190612e24565b6101cb6101e63660046124df565b61096b565b6101cb61097c565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b610267612183565b61026f612183565b600061027961098b565b90506000670de0b6b3a76400006102b9836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b90610c41565b816102c057fe5b838552046020808501829052604080516317caf6f160e01b815290519293506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926317caf6f192600480840193919291829003018186803b15801561032d57600080fd5b505afa158015610341573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103659190612831565b8360400181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156103c757600080fd5b505afa1580156103db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ff9190612831565b8360a00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561046157600080fd5b505afa158015610475573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104999190612831565b8360600181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156104fb57600080fd5b505afa15801561050f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105339190612831565b8360c00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561059557600080fd5b505afa1580156105a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105cd9190612831565b8360800181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b15801561062f57600080fd5b505afa158015610643573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106679190612831565b60e08401526106987f0000000000000000000000000000000000000000000000000000000000000000838d8d610c78565b6101008401526106ca7f0000000000000000000000000000000000000000000000000000000000000000838b8b610c78565b6101208401526106dd8282878a8a610ea8565b61014084015250909998505050505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b031614806107f557507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b0316145b61081a5760405162461bcd60e51b815260040161081190612cc6565b60405180910390fd5b600061082461098b565b905061083285828686610c78565b95945050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b0316146108b25760405162461bcd60e51b815260040161081190612c62565b60006108bc61098b565b90506000670de0b6b3a76400006108f6836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b816108fd57fe5b04905061090d8282888888610ea8565b979650505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000670de0b6b3a764000061095b61095261098b565b6102b385610a86565b8161096257fe5b0490505b919050565b600061097682610a86565b92915050565b600061098661098b565b905090565b60006003610a796109dc7f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611297565b610a73610a297f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611297565b610a737f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611297565b9061143c565b81610a8057fe5b04905090565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415610ad15750670de0b6b3a7640000610966565b60405163e6a4390560e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e6a4390590610b429086907f000000000000000000000000000000000000000000000000000000000000000090600401612ba5565b60206040518083038186803b158015610b5a57600080fd5b505afa158015610b6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b9291906124fb565b90506001600160a01b038116610bac576000915050610966565b610c3a81826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015610be957600080fd5b505afa158015610bfd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2191906124fb565b6001600160a01b0316856001600160a01b031614611297565b9392505050565b6000811580610c5c57505080820282828281610c5957fe5b04145b6109765760405162461bcd60e51b815260040161081190612d37565b606081818167ffffffffffffffff81118015610c9357600080fd5b50604051908082528060200260200182016040528015610ccd57816020015b610cba6121dd565b815260200190600190039081610cb25790505b5090506000876001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610d0b57600080fd5b505afa158015610d1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d439190612831565b90506000886001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610d8057600080fd5b505afa158015610d94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610db89190612831565b905060005b84811015610e9a576000888883818110610dd357fe5b905060200201359050610de4612269565b604051631526fe2760e01b81526001600160a01b038d1690631526fe2790610e10908590600401612e24565b60806040518083038186803b158015610e2857600080fd5b505afa158015610e3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6091906126aa565b9050610e798c8c84846000015185602001518a8a61145f565b868481518110610e8557fe5b60209081029190910101525050600101610dbd565b509198975050505050505050565b6060610eb261229a565b60405180606001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610f4557600080fd5b505afa158015610f59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f7d9190612831565b81526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610fdb57600080fd5b505afa158015610fef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110139190612831565b905290508260608167ffffffffffffffff8111801561103157600080fd5b5060405190808252806020026020018201604052801561106b57816020015b6110586122c4565b8152602001906001900390816110505790505b50905060005b8281101561128a57600087878381811061108757fe5b905060200201359050611098612373565b8551604051631526fe2760e01b81526001600160a01b0390911690631526fe27906110c7908590600401612e24565b6101206040518083038186803b1580156110e057600080fd5b505afa1580156110f4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061111891906126fc565b90506111226123bf565b86516040516393f1a40b60e01b81526001600160a01b03909116906393f1a40b906111539086908f90600401612e2d565b60606040518083038186803b15801561116b57600080fd5b505afa15801561117f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a391906127a0565b9050828585815181106111b257fe5b602090810291909101015152865185518690869081106111ce57fe5b602002602001015161012001906001600160a01b031690816001600160a01b031681525050866020015185858151811061120457fe5b6020026020010151610160018181525050866040015185858151811061122657fe5b602002602001015161018001818152505061127f8d670de0b6b3a764000061125b8f8b60400151610c4190919063ffffffff16565b8161126257fe5b048d88888151811061127057fe5b602002602001015186866117a9565b505050600101611071565b5098975050505050505050565b6000806000846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b1580156112d557600080fd5b505afa1580156112e9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061130d91906127dd565b506001600160701b031691506001600160701b0316915060006113a8866001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561136257600080fd5b505afa158015611376573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061139a91906124fb565b6001600160a01b0316611c7f565b60ff16905060006113eb876001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561136257600080fd5b60ff16905085156114295761141e83611418866114138661140d87601261143c565b90611d40565b611d63565b90611d7f565b945050505050610976565b61141e84611418856114138561140d8860125b818101818110156109765760405162461bcd60e51b815260040161081190612c32565b6114676121dd565b6000856001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156114a257600080fd5b505afa1580156114b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114da91906128a9565b60ff169050600061155e876001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561151d57600080fd5b505afa158015611531573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115559190612831565b83601203611d63565b905060006115ea886001600160a01b03166370a082318d6040518263ffffffff1660e01b81526004016115919190612b91565b60206040518083038186803b1580156115a957600080fd5b505afa1580156115bd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115e19190612831565b84601203611d63565b90506000670de0b6b3a76400006116048c6102b38c611db1565b8161160b57fe5b0490506000896001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561164957600080fd5b505afa15801561165d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061168191906124fb565b905060008a6001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156116be57600080fd5b505afa1580156116d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116f691906124fb565b9050604051806101a001604052808d81526020018b81526020018c6001600160a01b03168152602001836001600160a01b03168152602001826001600160a01b0316815260200161174f846001600160a01b03166120b0565b8152602001611766836001600160a01b03166120b0565b81526020018481526020018681526020018f6001600160a01b031681526020018581526020018a8152602001898152509650505050505050979650505050505050565b6000826000015190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b1580156117ed57600080fd5b505afa158015611801573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061182591906124fb565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561186257600080fd5b505afa158015611876573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189a91906124fb565b6020808701516001600160601b0316908801526001600160a01b0380851660408901528381166060890181905290821660808901529091506118db906120b0565b60a08701526118f26001600160a01b0382166120b0565b60c0870152670de0b6b3a764000061190d8a6102b386611db1565b8161191457fe5b048660e0018181525050826001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561195757600080fd5b505afa15801561196b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061198f9190612831565b6101008088019190915285015161014087015283516101a0870152855160405160016232bd9d60e01b031981526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163ffcd4263916119fc91908b90600401612e2d565b60006040518083038186803b158015611a1457600080fd5b505afa158015611a28573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611a509190810190612849565b5050506101c087015260c085015163ffffffff166127101415611a7b57600019610220870152611aa0565b60c08501516127109063ffffffff1680820390820281611a9757fe5b04016102208701525b50505061010082015115801590611abb575061010083015115155b8015611acb575061016083015115155b8015611ada575060e083015115155b15611c77576000836101600151611b0f6301e133806102b386602001516001600160601b03168a610c4190919063ffffffff16565b81611b1657fe5b0490506000846101000151611b3d8661014001518760e00151610c4190919063ffffffff16565b81611b4457fe5b04905080611b53575050611c77565b61271081611b84670de0b6b3a76400006102b38860c0015163ffffffff166127100387610c4190919063ffffffff16565b81611b8b57fe5b0481611b9357fe5b046101e086015260e084015115801590611bad5750825115155b15611c305761010084015160e0860151845160009291611bcd9190610c41565b81611bd457fe5b04905061271081611c14670de0b6b3a76400006102b38960e001516114188a604001516102b38d60c0015163ffffffff168c610c4190919063ffffffff16565b81611c1b57fe5b0481611c2357fe5b0461020087015250611c74565b61271081611c5d670de0b6b3a76400006102b38860c0015163ffffffff1687610c4190919063ffffffff16565b81611c6457fe5b0481611c6c57fe5b046102008601525b50505b505050505050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b179052905160009182916060916001600160a01b03861691611cc69190612b75565b600060405180830381855afa9150503d8060008114611d01576040519150601f19603f3d011682016040523d82523d6000602084013e611d06565b606091505b5091509150818015611d19575080516020145b611d24576012611d38565b80806020019051810190611d3891906128a9565b949350505050565b808203828111156109765760405162461bcd60e51b815260040161081190612c99565b600081611d71575081610976565b610c3a83600a84900a610c41565b6000808211611da05760405162461bcd60e51b815260040161081190612d08565b818381611da957fe5b049392505050565b6000807f00000000000000000000000000000000000000000000000000000000000000009050600080846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015611e1357600080fd5b505afa158015611e27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e4b91906127dd565b506001600160701b031691506001600160701b031691506000856001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015611e9d57600080fd5b505afa158015611eb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ed591906124fb565b90506000866001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015611f1257600080fd5b505afa158015611f26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f4a91906124fb565b90506000611f60836001600160a01b0316611c7f565b60ff1690506000611f79836001600160a01b0316611c7f565b60ff169050611f8d86611413601285611d40565b9550611f9e85611413601284611d40565b9450600080886001600160a01b0316866001600160a01b03161415611fda57670de0b6b3a76400009150611fd38b6001611297565b9050612079565b886001600160a01b0316856001600160a01b0316141561201157611fff8b6000611297565b9150670de0b6b3a76400009050612079565b61201a86610a86565b915061202585610a86565b90508161205c57670de0b6b3a764000061204460026102b38a85610c41565b8161204b57fe5b049950505050505050505050610966565b8061207957670de0b6b3a764000061204460026102b38b86610c41565b670de0b6b3a764000061209961208f8984610c41565b610a738b86610c41565b816120a057fe5b049b9a5050505050505050505050565b60408051600481526024810182526020810180516001600160e01b03166395d89b4160e01b179052905160609160009183916001600160a01b038616916120f79190612b75565b600060405180830381855afa9150503d8060008114612132576040519150601f19603f3d011682016040523d82523d6000602084013e612137565b606091505b509150915081801561214a575060008151115b61216f57604051806040016040528060038152602001623f3f3f60e81b815250611d38565b80806020019051810190611d389190612677565b60405180610160016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016060815260200160608152602001606081525090565b604051806101a00160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806080016040528060006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b604051806102400160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915290565b60405180606001604052806000815260200160008152602001600081525090565b805161097681612e9b565b60008083601f8401126123fc578182fd5b50813567ffffffffffffffff811115612413578182fd5b602083019150836020808302850101111561242d57600080fd5b9250929050565b600082601f830112612444578081fd5b815167ffffffffffffffff81111561245a578182fd5b61246d601f8201601f1916602001612e44565b915080825283602082850101111561248457600080fd5b612495816020840160208601612e6b565b5092915050565b805163ffffffff8116811461097657600080fd5b805167ffffffffffffffff8116811461097657600080fd5b80516001600160601b038116811461097657600080fd5b6000602082840312156124f0578081fd5b8135610c3a81612e9b565b60006020828403121561250c578081fd5b8151610c3a81612e9b565b60008060008060008060006080888a031215612531578283fd5b873567ffffffffffffffff80821115612548578485fd5b6125548b838c016123eb565b909950975060208a013591508082111561256c578485fd5b6125788b838c016123eb565b909750955060408a0135915080821115612590578485fd5b5061259d8a828b016123eb565b90945092505060608801356125b181612e9b565b8091505092959891949750929550565b600080600080606085870312156125d6578384fd5b84356125e181612e9b565b935060208501356125f181612e9b565b9250604085013567ffffffffffffffff81111561260c578283fd5b612618878288016123eb565b95989497509550505050565b600080600060408486031215612638578283fd5b833561264381612e9b565b9250602084013567ffffffffffffffff81111561265e578283fd5b61266a868287016123eb565b9497909650939450505050565b600060208284031215612688578081fd5b815167ffffffffffffffff81111561269e578182fd5b611d3884828501612434565b6000608082840312156126bb578081fd5b6126c56080612e44565b82516126d081612e9b565b808252506020830151602082015260408301516040820152606083015160608201528091505092915050565b600061012080838503121561270f578182fd5b61271881612e44565b905061272484846123e0565b815261273384602085016124c8565b6020820152604083015160408201526060830151606082015261275984608085016124b0565b608082015261276b8460a085016123e0565b60a082015261277d8460c0850161249c565b60c082015260e08381015190820152610100928301519281019290925250919050565b6000606082840312156127b1578081fd5b6127bb6060612e44565b8251815260208301516020820152604083015160408201528091505092915050565b6000806000606084860312156127f1578081fd5b83516127fc81612eb3565b602085015190935061280d81612eb3565b604085015190925063ffffffff81168114612826578182fd5b809150509250925092565b600060208284031215612842578081fd5b5051919050565b6000806000806080858703121561285e578182fd5b84519350602085015161287081612e9b565b604086015190935067ffffffffffffffff81111561288c578283fd5b61289887828801612434565b606096909601519497939650505050565b6000602082840312156128ba578081fd5b815160ff81168114610c3a578182fd5b6000610240825184526020830151602085015260408301516128ef60408601826129d5565b50606083015161290260608601826129d5565b50608083015161291560808601826129d5565b5060a08301518160a086015261292d82860182612b49565b91505060c083015184820360c08601526129478282612b49565b91505060e083015160e085015261010080840151818601525061012080840151612973828701826129d5565b50506101408381015190850152610160808401519085015261018080840151908501526101a080840151908501526101c080840151908501526101e0808401519085015261020080840151908501526102209283015192909301919091525090565b6001600160a01b03169052565b6000815180845260208085018081965082840281019150828601855b85811015612a28578284038952612a168483516128ca565b988501989350908401906001016129fe565b5091979650505050505050565b6000815180845260208085019450848183028601828601855b85811015612b3c57838303895281516101a0815185528682015187860152604080830151612a7e828801826129d5565b5050606080830151612a92828801826129d5565b5050608080830151612aa6828801826129d5565b505060a0808301518282880152612abf83880182612b49565b9250505060c08083015186830382880152612ada8382612b49565b9250505060e080830151818701525061010080830151818701525061012080830151612b08828801826129d5565b5050610140828101519086015261016080830151908601526101809182015191909401529784019790840190600101612a4e565b5090979650505050505050565b60008151808452612b61816020860160208601612e6b565b601f01601f19169290920160200192915050565b60008251612b87818460208701612e6b565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6000602080830181845280855180835260408601915060408482028701019250838701855b82811015612c1257603f19888603018452612c008583516128ca565b94509285019290850190600101612be4565b5092979650505050505050565b600060208252610c3a6020830184612a35565b602080825260169082015275536166654d6174683a20416464204f766572666c6f7760501b604082015260600190565b60208082526019908201527f4661726d4c656e7356323a204f6e6c7920666f7220424d434a00000000000000604082015260600190565b602080825260139082015272536166654d6174683a20556e646572666c6f7760681b604082015260600190565b60208082526022908201527f4661726d4c656e7356323a206f6e6c7920666f72204d43563220616e64204d43604082015261563360f01b606082015260800190565b602080825260159082015274536166654d6174683a20446976206279205a65726f60581b604082015260600190565b602080825260169082015275536166654d6174683a204d756c204f766572666c6f7760501b604082015260600190565b60006020825282516020830152602083015160408301526040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015160e083015260e08301516101008181850152808501519150506101606101208181860152612ddd610180860184612a35565b9250808601519050601f19610140818786030181880152612dfe8584612a35565b908801518782039092018488015293509050612e1a83826129e2565b9695505050505050565b90815260200190565b9182526001600160a01b0316602082015260400190565b60405181810167ffffffffffffffff81118282101715612e6357600080fd5b604052919050565b60005b83811015612e86578181015183820152602001612e6e565b83811115612e95576000848401525b50505050565b6001600160a01b0381168114612eb057600080fd5b50565b6001600160701b0381168114612eb057600080fdfea2646970667358221220e79148a5b8b4605cc16f9b893c0762257ac307c0da3da832151514c00184b62264736f6c634300060c0033", - "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100f55760003560e01c80638a38466e11610097578063cff5dd3311610066578063cff5dd33146101b0578063d02641a0146101b8578063eee5c276146101d8578063f97a496c146101eb576100f5565b80638a38466e146101605780639bbf1deb14610168578063b985a3a014610188578063ce7a198914610190576100f5565b806335541641116100d357806335541641146101285780634e57afe014610148578063685f02e71461015057806387dabe4614610158576100f5565b80630d1dcd9a146100fa578063117be4c2146101185780632c9e2b0514610120575b600080fd5b6101026101f3565b60405161010f9190612b91565b60405180910390f35b610102610217565b61010261023b565b61013b610136366004612517565b61025f565b60405161010f9190612d67565b6101026106f2565b610102610716565b61010261073a565b61010261075e565b61017b610176366004612624565b610782565b60405161010f9190612c1f565b61010261083b565b6101a361019e3660046125c1565b61085f565b60405161010f9190612bbf565b610102610918565b6101cb6101c63660046124df565b61093c565b60405161010f9190612e24565b6101cb6101e63660046124df565b61096b565b6101cb61097c565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b610267612183565b61026f612183565b600061027961098b565b90506000670de0b6b3a76400006102b9836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b90610c41565b816102c057fe5b838552046020808501829052604080516317caf6f160e01b815290519293506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926317caf6f192600480840193919291829003018186803b15801561032d57600080fd5b505afa158015610341573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103659190612831565b8360400181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156103c757600080fd5b505afa1580156103db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ff9190612831565b8360a00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561046157600080fd5b505afa158015610475573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104999190612831565b8360600181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156104fb57600080fd5b505afa15801561050f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105339190612831565b8360c00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561059557600080fd5b505afa1580156105a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105cd9190612831565b8360800181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b15801561062f57600080fd5b505afa158015610643573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106679190612831565b60e08401526106987f0000000000000000000000000000000000000000000000000000000000000000838d8d610c78565b6101008401526106ca7f0000000000000000000000000000000000000000000000000000000000000000838b8b610c78565b6101208401526106dd8282878a8a610ea8565b61014084015250909998505050505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b031614806107f557507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b0316145b61081a5760405162461bcd60e51b815260040161081190612cc6565b60405180910390fd5b600061082461098b565b905061083285828686610c78565b95945050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b0316146108b25760405162461bcd60e51b815260040161081190612c62565b60006108bc61098b565b90506000670de0b6b3a76400006108f6836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b816108fd57fe5b04905061090d8282888888610ea8565b979650505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000670de0b6b3a764000061095b61095261098b565b6102b385610a86565b8161096257fe5b0490505b919050565b600061097682610a86565b92915050565b600061098661098b565b905090565b60006003610a796109dc7f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611297565b610a73610a297f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611297565b610a737f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611297565b9061143c565b81610a8057fe5b04905090565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415610ad15750670de0b6b3a7640000610966565b60405163e6a4390560e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e6a4390590610b429086907f000000000000000000000000000000000000000000000000000000000000000090600401612ba5565b60206040518083038186803b158015610b5a57600080fd5b505afa158015610b6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b9291906124fb565b90506001600160a01b038116610bac576000915050610966565b610c3a81826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015610be957600080fd5b505afa158015610bfd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2191906124fb565b6001600160a01b0316856001600160a01b031614611297565b9392505050565b6000811580610c5c57505080820282828281610c5957fe5b04145b6109765760405162461bcd60e51b815260040161081190612d37565b606081818167ffffffffffffffff81118015610c9357600080fd5b50604051908082528060200260200182016040528015610ccd57816020015b610cba6121dd565b815260200190600190039081610cb25790505b5090506000876001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610d0b57600080fd5b505afa158015610d1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d439190612831565b90506000886001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610d8057600080fd5b505afa158015610d94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610db89190612831565b905060005b84811015610e9a576000888883818110610dd357fe5b905060200201359050610de4612269565b604051631526fe2760e01b81526001600160a01b038d1690631526fe2790610e10908590600401612e24565b60806040518083038186803b158015610e2857600080fd5b505afa158015610e3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6091906126aa565b9050610e798c8c84846000015185602001518a8a61145f565b868481518110610e8557fe5b60209081029190910101525050600101610dbd565b509198975050505050505050565b6060610eb261229a565b60405180606001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610f4557600080fd5b505afa158015610f59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f7d9190612831565b81526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610fdb57600080fd5b505afa158015610fef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110139190612831565b905290508260608167ffffffffffffffff8111801561103157600080fd5b5060405190808252806020026020018201604052801561106b57816020015b6110586122c4565b8152602001906001900390816110505790505b50905060005b8281101561128a57600087878381811061108757fe5b905060200201359050611098612373565b8551604051631526fe2760e01b81526001600160a01b0390911690631526fe27906110c7908590600401612e24565b6101206040518083038186803b1580156110e057600080fd5b505afa1580156110f4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061111891906126fc565b90506111226123bf565b86516040516393f1a40b60e01b81526001600160a01b03909116906393f1a40b906111539086908f90600401612e2d565b60606040518083038186803b15801561116b57600080fd5b505afa15801561117f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a391906127a0565b9050828585815181106111b257fe5b602090810291909101015152865185518690869081106111ce57fe5b602002602001015161012001906001600160a01b031690816001600160a01b031681525050866020015185858151811061120457fe5b6020026020010151610160018181525050866040015185858151811061122657fe5b602002602001015161018001818152505061127f8d670de0b6b3a764000061125b8f8b60400151610c4190919063ffffffff16565b8161126257fe5b048d88888151811061127057fe5b602002602001015186866117a9565b505050600101611071565b5098975050505050505050565b6000806000846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b1580156112d557600080fd5b505afa1580156112e9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061130d91906127dd565b506001600160701b031691506001600160701b0316915060006113a8866001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561136257600080fd5b505afa158015611376573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061139a91906124fb565b6001600160a01b0316611c7f565b60ff16905060006113eb876001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561136257600080fd5b60ff16905085156114295761141e83611418866114138661140d87601261143c565b90611d40565b611d63565b90611d7f565b945050505050610976565b61141e84611418856114138561140d8860125b818101818110156109765760405162461bcd60e51b815260040161081190612c32565b6114676121dd565b6000856001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156114a257600080fd5b505afa1580156114b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114da91906128a9565b60ff169050600061155e876001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561151d57600080fd5b505afa158015611531573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115559190612831565b83601203611d63565b905060006115ea886001600160a01b03166370a082318d6040518263ffffffff1660e01b81526004016115919190612b91565b60206040518083038186803b1580156115a957600080fd5b505afa1580156115bd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115e19190612831565b84601203611d63565b90506000670de0b6b3a76400006116048c6102b38c611db1565b8161160b57fe5b0490506000896001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561164957600080fd5b505afa15801561165d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061168191906124fb565b905060008a6001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156116be57600080fd5b505afa1580156116d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116f691906124fb565b9050604051806101a001604052808d81526020018b81526020018c6001600160a01b03168152602001836001600160a01b03168152602001826001600160a01b0316815260200161174f846001600160a01b03166120b0565b8152602001611766836001600160a01b03166120b0565b81526020018481526020018681526020018f6001600160a01b031681526020018581526020018a8152602001898152509650505050505050979650505050505050565b6000826000015190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b1580156117ed57600080fd5b505afa158015611801573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061182591906124fb565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561186257600080fd5b505afa158015611876573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189a91906124fb565b6020808701516001600160601b0316908801526001600160a01b0380851660408901528381166060890181905290821660808901529091506118db906120b0565b60a08701526118f26001600160a01b0382166120b0565b60c0870152670de0b6b3a764000061190d8a6102b386611db1565b8161191457fe5b048660e0018181525050826001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561195757600080fd5b505afa15801561196b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061198f9190612831565b6101008088019190915285015161014087015283516101a0870152855160405160016232bd9d60e01b031981526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163ffcd4263916119fc91908b90600401612e2d565b60006040518083038186803b158015611a1457600080fd5b505afa158015611a28573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611a509190810190612849565b5050506101c087015260c085015163ffffffff166127101415611a7b57600019610220870152611aa0565b60c08501516127109063ffffffff1680820390820281611a9757fe5b04016102208701525b50505061010082015115801590611abb575061010083015115155b8015611acb575061016083015115155b8015611ada575060e083015115155b15611c77576000836101600151611b0f6301e133806102b386602001516001600160601b03168a610c4190919063ffffffff16565b81611b1657fe5b0490506000846101000151611b3d8661014001518760e00151610c4190919063ffffffff16565b81611b4457fe5b04905080611b53575050611c77565b61271081611b84670de0b6b3a76400006102b38860c0015163ffffffff166127100387610c4190919063ffffffff16565b81611b8b57fe5b0481611b9357fe5b046101e086015260e084015115801590611bad5750825115155b15611c305761010084015160e0860151845160009291611bcd9190610c41565b81611bd457fe5b04905061271081611c14670de0b6b3a76400006102b38960e001516114188a604001516102b38d60c0015163ffffffff168c610c4190919063ffffffff16565b81611c1b57fe5b0481611c2357fe5b0461020087015250611c74565b61271081611c5d670de0b6b3a76400006102b38860c0015163ffffffff1687610c4190919063ffffffff16565b81611c6457fe5b0481611c6c57fe5b046102008601525b50505b505050505050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b179052905160009182916060916001600160a01b03861691611cc69190612b75565b600060405180830381855afa9150503d8060008114611d01576040519150601f19603f3d011682016040523d82523d6000602084013e611d06565b606091505b5091509150818015611d19575080516020145b611d24576012611d38565b80806020019051810190611d3891906128a9565b949350505050565b808203828111156109765760405162461bcd60e51b815260040161081190612c99565b600081611d71575081610976565b610c3a83600a84900a610c41565b6000808211611da05760405162461bcd60e51b815260040161081190612d08565b818381611da957fe5b049392505050565b6000807f00000000000000000000000000000000000000000000000000000000000000009050600080846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015611e1357600080fd5b505afa158015611e27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e4b91906127dd565b506001600160701b031691506001600160701b031691506000856001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015611e9d57600080fd5b505afa158015611eb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ed591906124fb565b90506000866001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015611f1257600080fd5b505afa158015611f26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f4a91906124fb565b90506000611f60836001600160a01b0316611c7f565b60ff1690506000611f79836001600160a01b0316611c7f565b60ff169050611f8d86611413601285611d40565b9550611f9e85611413601284611d40565b9450600080886001600160a01b0316866001600160a01b03161415611fda57670de0b6b3a76400009150611fd38b6001611297565b9050612079565b886001600160a01b0316856001600160a01b0316141561201157611fff8b6000611297565b9150670de0b6b3a76400009050612079565b61201a86610a86565b915061202585610a86565b90508161205c57670de0b6b3a764000061204460026102b38a85610c41565b8161204b57fe5b049950505050505050505050610966565b8061207957670de0b6b3a764000061204460026102b38b86610c41565b670de0b6b3a764000061209961208f8984610c41565b610a738b86610c41565b816120a057fe5b049b9a5050505050505050505050565b60408051600481526024810182526020810180516001600160e01b03166395d89b4160e01b179052905160609160009183916001600160a01b038616916120f79190612b75565b600060405180830381855afa9150503d8060008114612132576040519150601f19603f3d011682016040523d82523d6000602084013e612137565b606091505b509150915081801561214a575060008151115b61216f57604051806040016040528060038152602001623f3f3f60e81b815250611d38565b80806020019051810190611d389190612677565b60405180610160016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016060815260200160608152602001606081525090565b604051806101a00160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806080016040528060006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b604051806102400160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915290565b60405180606001604052806000815260200160008152602001600081525090565b805161097681612e9b565b60008083601f8401126123fc578182fd5b50813567ffffffffffffffff811115612413578182fd5b602083019150836020808302850101111561242d57600080fd5b9250929050565b600082601f830112612444578081fd5b815167ffffffffffffffff81111561245a578182fd5b61246d601f8201601f1916602001612e44565b915080825283602082850101111561248457600080fd5b612495816020840160208601612e6b565b5092915050565b805163ffffffff8116811461097657600080fd5b805167ffffffffffffffff8116811461097657600080fd5b80516001600160601b038116811461097657600080fd5b6000602082840312156124f0578081fd5b8135610c3a81612e9b565b60006020828403121561250c578081fd5b8151610c3a81612e9b565b60008060008060008060006080888a031215612531578283fd5b873567ffffffffffffffff80821115612548578485fd5b6125548b838c016123eb565b909950975060208a013591508082111561256c578485fd5b6125788b838c016123eb565b909750955060408a0135915080821115612590578485fd5b5061259d8a828b016123eb565b90945092505060608801356125b181612e9b565b8091505092959891949750929550565b600080600080606085870312156125d6578384fd5b84356125e181612e9b565b935060208501356125f181612e9b565b9250604085013567ffffffffffffffff81111561260c578283fd5b612618878288016123eb565b95989497509550505050565b600080600060408486031215612638578283fd5b833561264381612e9b565b9250602084013567ffffffffffffffff81111561265e578283fd5b61266a868287016123eb565b9497909650939450505050565b600060208284031215612688578081fd5b815167ffffffffffffffff81111561269e578182fd5b611d3884828501612434565b6000608082840312156126bb578081fd5b6126c56080612e44565b82516126d081612e9b565b808252506020830151602082015260408301516040820152606083015160608201528091505092915050565b600061012080838503121561270f578182fd5b61271881612e44565b905061272484846123e0565b815261273384602085016124c8565b6020820152604083015160408201526060830151606082015261275984608085016124b0565b608082015261276b8460a085016123e0565b60a082015261277d8460c0850161249c565b60c082015260e08381015190820152610100928301519281019290925250919050565b6000606082840312156127b1578081fd5b6127bb6060612e44565b8251815260208301516020820152604083015160408201528091505092915050565b6000806000606084860312156127f1578081fd5b83516127fc81612eb3565b602085015190935061280d81612eb3565b604085015190925063ffffffff81168114612826578182fd5b809150509250925092565b600060208284031215612842578081fd5b5051919050565b6000806000806080858703121561285e578182fd5b84519350602085015161287081612e9b565b604086015190935067ffffffffffffffff81111561288c578283fd5b61289887828801612434565b606096909601519497939650505050565b6000602082840312156128ba578081fd5b815160ff81168114610c3a578182fd5b6000610240825184526020830151602085015260408301516128ef60408601826129d5565b50606083015161290260608601826129d5565b50608083015161291560808601826129d5565b5060a08301518160a086015261292d82860182612b49565b91505060c083015184820360c08601526129478282612b49565b91505060e083015160e085015261010080840151818601525061012080840151612973828701826129d5565b50506101408381015190850152610160808401519085015261018080840151908501526101a080840151908501526101c080840151908501526101e0808401519085015261020080840151908501526102209283015192909301919091525090565b6001600160a01b03169052565b6000815180845260208085018081965082840281019150828601855b85811015612a28578284038952612a168483516128ca565b988501989350908401906001016129fe565b5091979650505050505050565b6000815180845260208085019450848183028601828601855b85811015612b3c57838303895281516101a0815185528682015187860152604080830151612a7e828801826129d5565b5050606080830151612a92828801826129d5565b5050608080830151612aa6828801826129d5565b505060a0808301518282880152612abf83880182612b49565b9250505060c08083015186830382880152612ada8382612b49565b9250505060e080830151818701525061010080830151818701525061012080830151612b08828801826129d5565b5050610140828101519086015261016080830151908601526101809182015191909401529784019790840190600101612a4e565b5090979650505050505050565b60008151808452612b61816020860160208601612e6b565b601f01601f19169290920160200192915050565b60008251612b87818460208701612e6b565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6000602080830181845280855180835260408601915060408482028701019250838701855b82811015612c1257603f19888603018452612c008583516128ca565b94509285019290850190600101612be4565b5092979650505050505050565b600060208252610c3a6020830184612a35565b602080825260169082015275536166654d6174683a20416464204f766572666c6f7760501b604082015260600190565b60208082526019908201527f4661726d4c656e7356323a204f6e6c7920666f7220424d434a00000000000000604082015260600190565b602080825260139082015272536166654d6174683a20556e646572666c6f7760681b604082015260600190565b60208082526022908201527f4661726d4c656e7356323a206f6e6c7920666f72204d43563220616e64204d43604082015261563360f01b606082015260800190565b602080825260159082015274536166654d6174683a20446976206279205a65726f60581b604082015260600190565b602080825260169082015275536166654d6174683a204d756c204f766572666c6f7760501b604082015260600190565b60006020825282516020830152602083015160408301526040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015160e083015260e08301516101008181850152808501519150506101606101208181860152612ddd610180860184612a35565b9250808601519050601f19610140818786030181880152612dfe8584612a35565b908801518782039092018488015293509050612e1a83826129e2565b9695505050505050565b90815260200190565b9182526001600160a01b0316602082015260400190565b60405181810167ffffffffffffffff81118282101715612e6357600080fd5b604052919050565b60005b83811015612e86578181015183820152602001612e6e565b83811115612e95576000848401525b50505050565b6001600160a01b0381168114612eb057600080fd5b50565b6001600160701b0381168114612eb057600080fdfea2646970667358221220e79148a5b8b4605cc16f9b893c0762257ac307c0da3da832151514c00184b62264736f6c634300060c0033", + "numDeployments": 2, + "solcInputHash": "05be5b065453cde7967331fef060caff", + "metadata": "{\"compiler\":{\"version\":\"0.6.12+commit.27d51765\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_joe\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"_wavax\",\"type\":\"address\"},{\"internalType\":\"contract IJoePair\",\"name\":\"_wavaxUsdte\",\"type\":\"address\"},{\"internalType\":\"contract IJoePair\",\"name\":\"_wavaxUsdce\",\"type\":\"address\"},{\"internalType\":\"contract IJoePair\",\"name\":\"_wavaxUsdc\",\"type\":\"address\"},{\"internalType\":\"contract IJoeFactory\",\"name\":\"_joeFactory\",\"type\":\"address\"},{\"internalType\":\"contract IMasterChef\",\"name\":\"_chefv2\",\"type\":\"address\"},{\"internalType\":\"contract IMasterChef\",\"name\":\"_chefv3\",\"type\":\"address\"},{\"internalType\":\"contract IBoostedMasterchef\",\"name\":\"_bmcj\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"bmcj\",\"outputs\":[{\"internalType\":\"contract IBoostedMasterchef\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"chefv2\",\"outputs\":[{\"internalType\":\"contract IMasterChef\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"chefv3\",\"outputs\":[{\"internalType\":\"contract IMasterChef\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPidsV2\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPidsV3\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPidsBMCJ\",\"type\":\"uint256[]\"},{\"internalType\":\"address\",\"name\":\"user\",\"type\":\"address\"}],\"name\":\"getAllFarmData\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"avaxPriceUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePriceUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAllocChefV2\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAllocChefV3\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAllocBMCJ\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePerSecChefV2\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePerSecChefV3\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePerSecBMCJ\",\"type\":\"uint256\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfo[]\",\"name\":\"farmInfosV2\",\"type\":\"tuple[]\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfo[]\",\"name\":\"farmInfosV3\",\"type\":\"tuple[]\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"baseApr\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"averageBoostedApr\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"veJoeShareBp\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePriceUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userLp\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userPendingJoe\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userBoostedApr\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userFactorShare\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfoBMCJ[]\",\"name\":\"farmInfosBMCJ\",\"type\":\"tuple[]\"}],\"internalType\":\"struct FarmLensV2.AllFarmData\",\"name\":\"\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getAvaxPrice\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"contract IBoostedMasterchef\",\"name\":\"chef\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"user\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPids\",\"type\":\"uint256[]\"}],\"name\":\"getBMCJFarmInfos\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"baseApr\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"averageBoostedApr\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"veJoeShareBp\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePriceUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userLp\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userPendingJoe\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userBoostedApr\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userFactorShare\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfoBMCJ[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"}],\"name\":\"getDerivedAvaxPriceOfToken\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"contract IMasterChef\",\"name\":\"chef\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPids\",\"type\":\"uint256[]\"}],\"name\":\"getMCFarmInfos\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfo[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"}],\"name\":\"getTokenPrice\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"joe\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"joeFactory\",\"outputs\":[{\"internalType\":\"contract IJoeFactory\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavax\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavaxUsdc\",\"outputs\":[{\"internalType\":\"contract IJoePair\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavaxUsdce\",\"outputs\":[{\"internalType\":\"contract IJoePair\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavaxUsdte\",\"outputs\":[{\"internalType\":\"contract IJoePair\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"getAllFarmData(uint256[],uint256[],uint256[],address)\":{\"params\":{\"user\":\"The address of the user, if address(0), returns global info\",\"whitelistedPidsBMCJ\":\"Array of all ids of pools that are whitelisted in BMCJ\",\"whitelistedPidsV2\":\"Array of all ids of pools that are whitelisted in chefV2\",\"whitelistedPidsV3\":\"Array of all ids of pools that are whitelisted in chefV3\"},\"returns\":{\"_0\":\"AllFarmData The information of all the whitelisted farms of MCV2, MCV3 and BMCJ\"}},\"getAvaxPrice()\":{\"returns\":{\"_0\":\"uint256 the avax price, scaled to 18 decimals\"}},\"getBMCJFarmInfos(address,address,uint256[])\":{\"params\":{\"chef\":\"The address of the MasterChef\",\"user\":\"The address of the user, if address(0), returns global info\",\"whitelistedPids\":\"Array of all ids of pools that are whitelisted and valid to have their farm data returned\"},\"returns\":{\"_0\":\"FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\"}},\"getDerivedAvaxPriceOfToken(address)\":{\"params\":{\"token\":\"The address of the token\"},\"returns\":{\"_0\":\"uint256 the token derived price, scaled to 18 decimals\"}},\"getMCFarmInfos(address,uint256[])\":{\"params\":{\"chef\":\"The address of the MasterChef\",\"whitelistedPids\":\"Array of all ids of pools that are whitelisted and valid to have their farm data returned\"},\"returns\":{\"_0\":\"FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\"}},\"getTokenPrice(address)\":{\"params\":{\"token\":\"The address of the token\"},\"returns\":{\"_0\":\"uint256 the Usd price of token, scaled to 18 decimals\"}}},\"stateVariables\":{\"SEC_PER_YEAR\":{\"details\":\"365 * 86400, hard coding it for gas optimisation\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"getAllFarmData(uint256[],uint256[],uint256[],address)\":{\"notice\":\"Get all data needed for useFarms hook.\"},\"getAvaxPrice()\":{\"notice\":\"Returns the price of avax in Usd\"},\"getBMCJFarmInfos(address,address,uint256[])\":{\"notice\":\"Returns the farm pairs data for BoostedMasterChefJoe\"},\"getDerivedAvaxPriceOfToken(address)\":{\"notice\":\"Returns the derived price of token, it needs to be paired with wavax\"},\"getMCFarmInfos(address,uint256[])\":{\"notice\":\"Returns the farm pairs data for MCV2 and MCV3\"},\"getTokenPrice(address)\":{\"notice\":\"Returns the Usd price of token, it needs to be paired with wavax\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"contracts/traderjoe/FarmLensV2.sol\":\"FarmLensV2\"},\"evmVersion\":\"istanbul\",\"libraries\":{\"__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"contracts/interfaces/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\n\\ninterface IERC20 {\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address account) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 amount) external returns (bool);\\n\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n\\n // EIP 2612\\n function permit(\\n address owner,\\n address spender,\\n uint256 value,\\n uint256 deadline,\\n uint8 v,\\n bytes32 r,\\n bytes32 s\\n ) external;\\n}\\n\",\"keccak256\":\"0xa3fb82796e80f566a5c47f9a1f2ade7de7f390dfdc06bea5375112b9f9314f40\",\"license\":\"MIT\"},\"contracts/libraries/SafeERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\n\\nimport \\\"../interfaces/IERC20.sol\\\";\\n\\nlibrary SafeERC20 {\\n function safeSymbol(IERC20 token) internal view returns (string memory) {\\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x95d89b41));\\n return success && data.length > 0 ? abi.decode(data, (string)) : \\\"???\\\";\\n }\\n\\n function safeName(IERC20 token) internal view returns (string memory) {\\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x06fdde03));\\n return success && data.length > 0 ? abi.decode(data, (string)) : \\\"???\\\";\\n }\\n\\n function safeDecimals(IERC20 token) internal view returns (uint8) {\\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x313ce567));\\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\\n }\\n\\n function safeTransfer(\\n IERC20 token,\\n address to,\\n uint256 amount\\n ) internal {\\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(0xa9059cbb, to, amount));\\n require(success && (data.length == 0 || abi.decode(data, (bool))), \\\"SafeERC20: Transfer failed\\\");\\n }\\n\\n function safeTransferFrom(\\n IERC20 token,\\n address from,\\n uint256 amount\\n ) internal {\\n (bool success, bytes memory data) = address(token).call(\\n abi.encodeWithSelector(0x23b872dd, from, address(this), amount)\\n );\\n require(success && (data.length == 0 || abi.decode(data, (bool))), \\\"SafeERC20: TransferFrom failed\\\");\\n }\\n}\\n\",\"keccak256\":\"0xdd77ee6d503b5396208d64e811ee89ca55389c62071003cc223f4ea0029c10ac\",\"license\":\"MIT\"},\"contracts/libraries/SafeMath.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\n\\n// a library for performing overflow-safe math, updated with awesomeness from of DappHub (https://github.com/dapphub/ds-math)\\nlibrary SafeMath {\\n function add(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require((c = a + b) >= b, \\\"SafeMath: Add Overflow\\\");\\n }\\n\\n function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require((c = a - b) <= a, \\\"SafeMath: Underflow\\\");\\n }\\n\\n function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require(b == 0 || (c = a * b) / b == a, \\\"SafeMath: Mul Overflow\\\");\\n }\\n\\n function div(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require(b > 0, \\\"SafeMath: Div by Zero\\\");\\n c = a / b;\\n }\\n\\n function to128(uint256 a) internal pure returns (uint128 c) {\\n require(a <= uint128(-1), \\\"SafeMath: uint128 Overflow\\\");\\n c = uint128(a);\\n }\\n}\\n\\nlibrary SafeMath128 {\\n function add(uint128 a, uint128 b) internal pure returns (uint128 c) {\\n require((c = a + b) >= b, \\\"SafeMath: Add Overflow\\\");\\n }\\n\\n function sub(uint128 a, uint128 b) internal pure returns (uint128 c) {\\n require((c = a - b) <= a, \\\"SafeMath: Underflow\\\");\\n }\\n}\\n\",\"keccak256\":\"0x8b8dcb649a07667a9a97c050a374a82389e7a19254abaebedf399c00619042a8\",\"license\":\"MIT\"},\"contracts/traderjoe/FarmLensV2.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\npragma experimental ABIEncoderV2;\\nimport \\\"../libraries/SafeMath.sol\\\";\\nimport \\\"../libraries/SafeERC20.sol\\\";\\n\\nimport \\\"./interfaces/IERC20.sol\\\";\\nimport \\\"./interfaces/IJoeERC20.sol\\\";\\nimport \\\"./interfaces/IJoePair.sol\\\";\\nimport \\\"./interfaces/IJoeFactory.sol\\\";\\n\\ninterface IMasterChef {\\n struct PoolInfo {\\n IJoeERC20 lpToken; // Address of LP token contract.\\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\\n }\\n\\n function poolLength() external view returns (uint256);\\n\\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\\n\\n function totalAllocPoint() external view returns (uint256);\\n\\n function joePerSec() external view returns (uint256);\\n}\\n\\ninterface IBoostedMasterchef {\\n struct UserInfo {\\n uint256 amount;\\n uint256 rewardDebt;\\n uint256 factor;\\n }\\n\\n struct PoolInfo {\\n IERC20 lpToken;\\n uint96 allocPoint;\\n uint256 accJoePerShare;\\n uint256 accJoePerFactorPerShare;\\n uint64 lastRewardTimestamp;\\n address rewarder;\\n uint32 veJoeShareBp;\\n uint256 totalFactor;\\n uint256 totalLpSupply;\\n }\\n\\n function userInfo(uint256 _pid, address user) external view returns (UserInfo memory);\\n\\n function pendingTokens(uint256 _pid, address user)\\n external\\n view\\n returns (\\n uint256,\\n address,\\n string memory,\\n uint256\\n );\\n\\n function poolLength() external view returns (uint256);\\n\\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\\n\\n function totalAllocPoint() external view returns (uint256);\\n\\n function joePerSec() external view returns (uint256);\\n}\\n\\ncontract FarmLensV2 {\\n using SafeMath for uint256;\\n using SafeERC20 for IERC20;\\n\\n struct FarmInfo {\\n uint256 id;\\n uint256 allocPoint;\\n address lpAddress;\\n address token0Address;\\n address token1Address;\\n string token0Symbol;\\n string token1Symbol;\\n uint256 reserveUsd;\\n uint256 totalSupplyScaled;\\n address chefAddress;\\n uint256 chefBalanceScaled;\\n uint256 chefTotalAlloc;\\n uint256 chefJoePerSec;\\n }\\n\\n struct FarmInfoBMCJ {\\n uint256 id;\\n uint256 allocPoint;\\n address lpAddress;\\n address token0Address;\\n address token1Address;\\n string token0Symbol;\\n string token1Symbol;\\n uint256 reserveUsd;\\n uint256 totalSupplyScaled;\\n address chefAddress;\\n uint256 chefBalanceScaled;\\n uint256 chefTotalAlloc;\\n uint256 chefJoePerSec;\\n uint256 baseApr;\\n uint256 averageBoostedApr;\\n uint256 veJoeShareBp;\\n uint256 joePriceUsd;\\n\\n uint256 userLp;\\n uint256 userPendingJoe;\\n uint256 userBoostedApr;\\n uint256 userFactorShare;\\n }\\n\\n struct AllFarmData {\\n uint256 avaxPriceUsd;\\n uint256 joePriceUsd;\\n uint256 totalAllocChefV2;\\n uint256 totalAllocChefV3;\\n uint256 totalAllocBMCJ;\\n uint256 joePerSecChefV2;\\n uint256 joePerSecChefV3;\\n uint256 joePerSecBMCJ;\\n FarmInfo[] farmInfosV2;\\n FarmInfo[] farmInfosV3;\\n FarmInfoBMCJ[] farmInfosBMCJ;\\n }\\n\\n struct GlobalInfo {\\n address chef;\\n uint256 totalAlloc;\\n uint256 joePerSec;\\n }\\n\\n /// @dev 365 * 86400, hard coding it for gas optimisation\\n uint256 private constant SEC_PER_YEAR = 31536000;\\n uint256 private constant BP_PRECISION = 10_000;\\n uint256 private constant PRECISION = 1e18;\\n\\n address public immutable joe; // 0x6e84a6216eA6dACC71eE8E6b0a5B7322EEbC0fDd;\\n address public immutable wavax; // 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7;\\n IJoePair public immutable wavaxUsdte; // 0xeD8CBD9F0cE3C6986b22002F03c6475CEb7a6256\\n IJoePair public immutable wavaxUsdce; // 0xA389f9430876455C36478DeEa9769B7Ca4E3DDB1\\n IJoePair public immutable wavaxUsdc; // 0xf4003f4efbe8691b60249e6afbd307abe7758adb\\n IJoeFactory public immutable joeFactory; // 0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10\\n IMasterChef public immutable chefv2; // 0xd6a4F121CA35509aF06A0Be99093d08462f53052\\n IMasterChef public immutable chefv3; // 0x188bED1968b795d5c9022F6a0bb5931Ac4c18F00\\n IBoostedMasterchef public immutable bmcj; // Not deployed yet\\n bool private immutable isWavaxToken1InWavaxUsdte;\\n bool private immutable isWavaxToken1InWavaxUsdce;\\n bool private immutable isWavaxToken1InWavaxUsdc;\\n\\n constructor(\\n address _joe,\\n address _wavax,\\n IJoePair _wavaxUsdte,\\n IJoePair _wavaxUsdce,\\n IJoePair _wavaxUsdc,\\n IJoeFactory _joeFactory,\\n IMasterChef _chefv2,\\n IMasterChef _chefv3,\\n IBoostedMasterchef _bmcj\\n ) public {\\n joe = _joe;\\n wavax = _wavax;\\n wavaxUsdte = _wavaxUsdte;\\n wavaxUsdce = _wavaxUsdce;\\n wavaxUsdc = _wavaxUsdc;\\n joeFactory = _joeFactory;\\n chefv2 = _chefv2;\\n chefv3 = _chefv3;\\n bmcj = _bmcj;\\n\\n isWavaxToken1InWavaxUsdte = _wavaxUsdte.token1() == _wavax;\\n isWavaxToken1InWavaxUsdce = _wavaxUsdce.token1() == _wavax;\\n isWavaxToken1InWavaxUsdc = _wavaxUsdc.token1() == _wavax;\\n }\\n\\n /// @notice Returns the price of avax in Usd\\n /// @return uint256 the avax price, scaled to 18 decimals\\n function getAvaxPrice() external view returns (uint256) {\\n return _getAvaxPrice();\\n }\\n\\n /// @notice Returns the derived price of token, it needs to be paired with wavax\\n /// @param token The address of the token\\n /// @return uint256 the token derived price, scaled to 18 decimals\\n function getDerivedAvaxPriceOfToken(address token) external view returns (uint256) {\\n return _getDerivedAvaxPriceOfToken(token);\\n }\\n\\n /// @notice Returns the Usd price of token, it needs to be paired with wavax\\n /// @param token The address of the token\\n /// @return uint256 the Usd price of token, scaled to 18 decimals\\n function getTokenPrice(address token) external view returns (uint256) {\\n return _getDerivedAvaxPriceOfToken(token).mul(_getAvaxPrice()) / 1e18;\\n }\\n\\n /// @notice Returns the farm pairs data for MCV2 and MCV3\\n /// @param chef The address of the MasterChef\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\\n function getMCFarmInfos(IMasterChef chef, uint256[] calldata whitelistedPids)\\n external\\n view\\n returns (FarmInfo[] memory)\\n {\\n require(chef == chefv2 || chef == chefv3, \\\"FarmLensV2: only for MCV2 and MCV3\\\");\\n\\n uint256 avaxPrice = _getAvaxPrice();\\n return _getMCFarmInfos(chef, avaxPrice, whitelistedPids);\\n }\\n\\n /// @notice Returns the farm pairs data for BoostedMasterChefJoe\\n /// @param chef The address of the MasterChef\\n /// @param user The address of the user, if address(0), returns global info\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\\n function getBMCJFarmInfos(\\n IBoostedMasterchef chef,\\n address user,\\n uint256[] calldata whitelistedPids\\n ) external view returns (FarmInfoBMCJ[] memory) {\\n require(chef == bmcj, \\\"FarmLensV2: Only for BMCJ\\\");\\n\\n uint256 avaxPrice = _getAvaxPrice();\\n uint256 joePrice = _getDerivedAvaxPriceOfToken(joe).mul(avaxPrice) / PRECISION;\\n return _getBMCJFarmInfos(avaxPrice, joePrice, user, whitelistedPids);\\n }\\n\\n /// @notice Get all data needed for useFarms hook.\\n /// @param whitelistedPidsV2 Array of all ids of pools that are whitelisted in chefV2\\n /// @param whitelistedPidsV3 Array of all ids of pools that are whitelisted in chefV3\\n /// @param whitelistedPidsBMCJ Array of all ids of pools that are whitelisted in BMCJ\\n /// @param user The address of the user, if address(0), returns global info\\n /// @return AllFarmData The information of all the whitelisted farms of MCV2, MCV3 and BMCJ\\n function getAllFarmData(\\n uint256[] calldata whitelistedPidsV2,\\n uint256[] calldata whitelistedPidsV3,\\n uint256[] calldata whitelistedPidsBMCJ,\\n address user\\n ) external view returns (AllFarmData memory) {\\n AllFarmData memory allFarmData;\\n\\n uint256 avaxPrice = _getAvaxPrice();\\n uint256 joePrice = _getDerivedAvaxPriceOfToken(joe).mul(avaxPrice) / PRECISION;\\n\\n allFarmData.avaxPriceUsd = avaxPrice;\\n allFarmData.joePriceUsd = joePrice;\\n\\n allFarmData.totalAllocChefV2 = chefv2.totalAllocPoint();\\n allFarmData.joePerSecChefV2 = chefv2.joePerSec();\\n\\n allFarmData.totalAllocChefV3 = chefv3.totalAllocPoint();\\n allFarmData.joePerSecChefV3 = chefv3.joePerSec();\\n\\n allFarmData.totalAllocBMCJ = bmcj.totalAllocPoint();\\n allFarmData.joePerSecBMCJ = bmcj.joePerSec();\\n\\n allFarmData.farmInfosV2 = _getMCFarmInfos(chefv2, avaxPrice, whitelistedPidsV2);\\n allFarmData.farmInfosV3 = _getMCFarmInfos(chefv3, avaxPrice, whitelistedPidsV3);\\n allFarmData.farmInfosBMCJ = _getBMCJFarmInfos(avaxPrice, joePrice, user, whitelistedPidsBMCJ);\\n\\n return allFarmData;\\n }\\n\\n /// @notice Returns the price of avax in Usd internally\\n /// @return uint256 the avax price, scaled to 18 decimals\\n function _getAvaxPrice() private view returns (uint256) {\\n return\\n _getDerivedTokenPriceOfPair(wavaxUsdte, isWavaxToken1InWavaxUsdte)\\n .add(_getDerivedTokenPriceOfPair(wavaxUsdce, isWavaxToken1InWavaxUsdce))\\n .add(_getDerivedTokenPriceOfPair(wavaxUsdc, isWavaxToken1InWavaxUsdc)) / 3;\\n }\\n\\n /// @notice Returns the derived price of token in the other token\\n /// @param pair The address of the pair\\n /// @param derivedtoken0 If price should be derived from token0 if true, or token1 if false\\n /// @return uint256 the derived price, scaled to 18 decimals\\n function _getDerivedTokenPriceOfPair(IJoePair pair, bool derivedtoken0) private view returns (uint256) {\\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\\n uint256 decimals0 = IERC20(pair.token0()).safeDecimals();\\n uint256 decimals1 = IERC20(pair.token1()).safeDecimals();\\n\\n if (derivedtoken0) {\\n return _scaleTo(reserve0, decimals1.add(18).sub(decimals0)).div(reserve1);\\n } else {\\n return _scaleTo(reserve1, decimals0.add(18).sub(decimals1)).div(reserve0);\\n }\\n }\\n\\n /// @notice Returns the derived price of token, it needs to be paired with wavax\\n /// @param token The address of the token\\n /// @return uint256 the token derived price, scaled to 18 decimals\\n function _getDerivedAvaxPriceOfToken(address token) private view returns (uint256) {\\n if (token == wavax) {\\n return PRECISION;\\n }\\n IJoePair pair = IJoePair(joeFactory.getPair(token, wavax));\\n if (address(pair) == address(0)) {\\n return 0;\\n }\\n // instead of testing wavax == pair.token0(), we do the opposite to save gas\\n return _getDerivedTokenPriceOfPair(pair, token == pair.token1());\\n }\\n\\n /// @notice Returns the amount scaled to decimals\\n /// @param amount The amount\\n /// @param decimals The decimals to scale `amount`\\n /// @return uint256 The amount scaled to decimals\\n function _scaleTo(uint256 amount, uint256 decimals) private pure returns (uint256) {\\n if (decimals == 0) return amount;\\n return amount.mul(10**decimals);\\n }\\n\\n /// @notice Returns the derived avax liquidity, at least one of the token needs to be paired with wavax\\n /// @param pair The address of the pair\\n /// @return uint256 the derived price of pair's liquidity, scaled to 18 decimals\\n function _getDerivedAvaxLiquidityOfPair(IJoePair pair) private view returns (uint256) {\\n address _wavax = wavax;\\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\\n IERC20 token0 = IERC20(pair.token0());\\n IERC20 token1 = IERC20(pair.token1());\\n uint256 decimals0 = token0.safeDecimals();\\n uint256 decimals1 = token1.safeDecimals();\\n\\n reserve0 = _scaleTo(reserve0, uint256(18).sub(decimals0));\\n reserve1 = _scaleTo(reserve1, uint256(18).sub(decimals1));\\n\\n uint256 token0DerivedAvaxPrice;\\n uint256 token1DerivedAvaxPrice;\\n if (address(token0) == _wavax) {\\n token0DerivedAvaxPrice = PRECISION;\\n token1DerivedAvaxPrice = _getDerivedTokenPriceOfPair(pair, true);\\n } else if (address(token1) == _wavax) {\\n token0DerivedAvaxPrice = _getDerivedTokenPriceOfPair(pair, false);\\n token1DerivedAvaxPrice = PRECISION;\\n } else {\\n token0DerivedAvaxPrice = _getDerivedAvaxPriceOfToken(address(token0));\\n token1DerivedAvaxPrice = _getDerivedAvaxPriceOfToken(address(token1));\\n // If one token isn't paired with wavax, then we hope that the second one is.\\n // E.g, TOKEN/UsdC, token might not be paired with wavax, but UsdC is.\\n // If both aren't paired with wavax, return 0\\n if (token0DerivedAvaxPrice == 0) return reserve1.mul(token1DerivedAvaxPrice).mul(2) / PRECISION;\\n if (token1DerivedAvaxPrice == 0) return reserve0.mul(token0DerivedAvaxPrice).mul(2) / PRECISION;\\n }\\n return reserve0.mul(token0DerivedAvaxPrice).add(reserve1.mul(token1DerivedAvaxPrice)) / PRECISION;\\n }\\n\\n /// @notice Private function to return the farm pairs data for a given MasterChef (V2 or V3)\\n /// @param chef The address of the MasterChef\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\\n function _getMCFarmInfos(\\n IMasterChef chef,\\n uint256 avaxPrice,\\n uint256[] calldata whitelistedPids\\n ) private view returns (FarmInfo[] memory) {\\n uint256 whitelistLength = whitelistedPids.length;\\n FarmInfo[] memory farmInfos = new FarmInfo[](whitelistLength);\\n\\n uint256 chefTotalAlloc = chef.totalAllocPoint();\\n uint256 chefJoePerSec = chef.joePerSec();\\n\\n for (uint256 i; i < whitelistLength; i++) {\\n uint256 pid = whitelistedPids[i];\\n IMasterChef.PoolInfo memory pool = chef.poolInfo(pid);\\n\\n farmInfos[i] = _getMCFarmInfo(\\n chef,\\n avaxPrice,\\n pid,\\n IJoePair(address(pool.lpToken)),\\n pool.allocPoint,\\n chefTotalAlloc,\\n chefJoePerSec\\n );\\n }\\n\\n return farmInfos;\\n }\\n\\n /// @notice Helper function to return the farm info of a given pool\\n /// @param chef The address of the MasterChef\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param pid The pid of the pool\\n /// @param lpToken The lpToken of the pool\\n /// @param allocPoint The allocPoint of the pool\\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\\n function _getMCFarmInfo(\\n IMasterChef chef,\\n uint256 avaxPrice,\\n uint256 pid,\\n IJoePair lpToken,\\n uint256 allocPoint,\\n uint256 totalAllocPoint,\\n uint256 chefJoePerSec\\n ) private view returns (FarmInfo memory) {\\n uint256 decimals = lpToken.decimals();\\n uint256 totalSupplyScaled = _scaleTo(lpToken.totalSupply(), 18 - decimals);\\n uint256 chefBalanceScaled = _scaleTo(lpToken.balanceOf(address(chef)), 18 - decimals);\\n uint256 reserveUsd = _getDerivedAvaxLiquidityOfPair(lpToken).mul(avaxPrice) / PRECISION;\\n IERC20 token0 = IERC20(lpToken.token0());\\n IERC20 token1 = IERC20(lpToken.token1());\\n\\n return\\n FarmInfo({\\n id: pid,\\n allocPoint: allocPoint,\\n lpAddress: address(lpToken),\\n token0Address: address(token0),\\n token1Address: address(token1),\\n token0Symbol: token0.safeSymbol(),\\n token1Symbol: token1.safeSymbol(),\\n reserveUsd: reserveUsd,\\n totalSupplyScaled: totalSupplyScaled,\\n chefBalanceScaled: chefBalanceScaled,\\n chefAddress: address(chef),\\n chefTotalAlloc: totalAllocPoint,\\n chefJoePerSec: chefJoePerSec\\n });\\n }\\n\\n /// @notice Private function to return the farm pairs data for boostedMasterChef\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param joePrice The joe price as a parameter to save gas\\n /// @param user The address of the user, if address(0), returns global info\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\\n function _getBMCJFarmInfos(\\n uint256 avaxPrice,\\n uint256 joePrice,\\n address user,\\n uint256[] calldata whitelistedPids\\n ) private view returns (FarmInfoBMCJ[] memory) {\\n GlobalInfo memory globalInfo = GlobalInfo(address(bmcj), bmcj.totalAllocPoint(), bmcj.joePerSec());\\n\\n uint256 whitelistLength = whitelistedPids.length;\\n FarmInfoBMCJ[] memory farmInfos = new FarmInfoBMCJ[](whitelistLength);\\n\\n for (uint256 i; i < whitelistLength; i++) {\\n uint256 pid = whitelistedPids[i];\\n IBoostedMasterchef.PoolInfo memory pool = IBoostedMasterchef(globalInfo.chef).poolInfo(pid);\\n IBoostedMasterchef.UserInfo memory userInfo;\\n userInfo = IBoostedMasterchef(globalInfo.chef).userInfo(pid, user);\\n\\n farmInfos[i].id = pid;\\n farmInfos[i].chefAddress = globalInfo.chef;\\n farmInfos[i].chefTotalAlloc = globalInfo.totalAlloc;\\n farmInfos[i].chefJoePerSec = globalInfo.joePerSec;\\n farmInfos[i].joePriceUsd = joePrice;\\n _getBMCJFarmInfo(\\n avaxPrice,\\n globalInfo.joePerSec.mul(joePrice) / PRECISION,\\n user,\\n farmInfos[i],\\n pool,\\n userInfo\\n );\\n }\\n\\n return farmInfos;\\n }\\n\\n /// @notice Helper function to return the farm info of a given pool of BMCJ\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param UsdPerSec The Usd per sec emitted to BMCJ\\n /// @param userAddress The address of the user\\n /// @param farmInfo The farmInfo of that pool\\n /// @param user The user information\\n function _getBMCJFarmInfo(\\n uint256 avaxPrice,\\n uint256 UsdPerSec,\\n address userAddress,\\n FarmInfoBMCJ memory farmInfo,\\n IBoostedMasterchef.PoolInfo memory pool,\\n IBoostedMasterchef.UserInfo memory user\\n ) private view {\\n {\\n IJoePair lpToken = IJoePair(address(pool.lpToken));\\n IERC20 token0 = IERC20(lpToken.token0());\\n IERC20 token1 = IERC20(lpToken.token1());\\n\\n farmInfo.allocPoint = pool.allocPoint;\\n farmInfo.lpAddress = address(lpToken);\\n farmInfo.token0Address = address(token0);\\n farmInfo.token1Address = address(token1);\\n farmInfo.token0Symbol = token0.safeSymbol();\\n farmInfo.token1Symbol = token1.safeSymbol();\\n farmInfo.reserveUsd = _getDerivedAvaxLiquidityOfPair(lpToken).mul(avaxPrice) / PRECISION;\\n // LP is in 18 decimals, so it's already scaled for JLP\\n farmInfo.totalSupplyScaled = lpToken.totalSupply();\\n farmInfo.chefBalanceScaled = pool.totalLpSupply;\\n farmInfo.userLp = user.amount;\\n farmInfo.veJoeShareBp = pool.veJoeShareBp;\\n (farmInfo.userPendingJoe, , , ) = bmcj.pendingTokens(farmInfo.id, userAddress);\\n }\\n\\n if (\\n pool.totalLpSupply != 0 &&\\n farmInfo.totalSupplyScaled != 0 &&\\n farmInfo.chefTotalAlloc != 0 &&\\n farmInfo.reserveUsd != 0\\n ) {\\n uint256 poolUsdPerYear = UsdPerSec.mul(pool.allocPoint).mul(SEC_PER_YEAR) / farmInfo.chefTotalAlloc;\\n\\n uint256 poolReserveUsd = farmInfo.reserveUsd.mul(farmInfo.chefBalanceScaled) / farmInfo.totalSupplyScaled;\\n\\n if (poolReserveUsd == 0) return;\\n\\n farmInfo.baseApr =\\n poolUsdPerYear.mul(BP_PRECISION - pool.veJoeShareBp).mul(PRECISION) /\\n poolReserveUsd /\\n BP_PRECISION;\\n\\n if (pool.totalFactor != 0) {\\n farmInfo.averageBoostedApr =\\n poolUsdPerYear.mul(pool.veJoeShareBp).mul(PRECISION) /\\n poolReserveUsd /\\n BP_PRECISION;\\n\\n if (user.amount != 0 && user.factor != 0) {\\n uint256 userLpUsd = user.amount.mul(farmInfo.reserveUsd) / pool.totalLpSupply;\\n\\n farmInfo.userBoostedApr =\\n poolUsdPerYear.mul(pool.veJoeShareBp).mul(user.factor).div(pool.totalFactor).mul(PRECISION) /\\n userLpUsd /\\n BP_PRECISION;\\n\\n farmInfo.userFactorShare = user.factor.mul(PRECISION) / pool.totalFactor;\\n }\\n }\\n }\\n }\\n}\\n\",\"keccak256\":\"0x93f525a9c2a0119a9aff852479f9f112f71f9ed66fb17424318768dadb32439a\",\"license\":\"MIT\"},\"contracts/traderjoe/interfaces/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IERC20Joe {\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n function name() external view returns (string memory);\\n\\n function symbol() external view returns (string memory);\\n\\n function decimals() external view returns (uint8);\\n\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address owner) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n function transferFrom(\\n address from,\\n address to,\\n uint256 value\\n ) external returns (bool);\\n}\\n\",\"keccak256\":\"0xd5d59683ac059dc8c7a528d9243a0434d727bcddd4e477d4b26d50ae4f78ea05\",\"license\":\"GPL-3.0\"},\"contracts/traderjoe/interfaces/IJoeERC20.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IJoeERC20 {\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n function name() external pure returns (string memory);\\n\\n function symbol() external pure returns (string memory);\\n\\n function decimals() external pure returns (uint8);\\n\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address owner) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n function transferFrom(\\n address from,\\n address to,\\n uint256 value\\n ) external returns (bool);\\n\\n function DOMAIN_SEPARATOR() external view returns (bytes32);\\n\\n function PERMIT_TYPEHASH() external pure returns (bytes32);\\n\\n function nonces(address owner) external view returns (uint256);\\n\\n function permit(\\n address owner,\\n address spender,\\n uint256 value,\\n uint256 deadline,\\n uint8 v,\\n bytes32 r,\\n bytes32 s\\n ) external;\\n}\\n\",\"keccak256\":\"0x0f9b1de8137e61afcf2c09fde27dc657da98b7c19c1811fd205ffbe877490d36\",\"license\":\"GPL-3.0\"},\"contracts/traderjoe/interfaces/IJoeFactory.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IJoeFactory {\\n event PairCreated(address indexed token0, address indexed token1, address pair, uint256);\\n\\n function feeTo() external view returns (address);\\n\\n function feeToSetter() external view returns (address);\\n\\n function migrator() external view returns (address);\\n\\n function getPair(address tokenA, address tokenB) external view returns (address pair);\\n\\n function allPairs(uint256) external view returns (address pair);\\n\\n function allPairsLength() external view returns (uint256);\\n\\n function createPair(address tokenA, address tokenB) external returns (address pair);\\n\\n function setFeeTo(address) external;\\n\\n function setFeeToSetter(address) external;\\n\\n function setMigrator(address) external;\\n}\\n\",\"keccak256\":\"0x0e31007ead341ae106c1ca874629b527886427f7f47641d96e0d172720f2c3ca\",\"license\":\"GPL-3.0\"},\"contracts/traderjoe/interfaces/IJoePair.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IJoePair {\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n function name() external pure returns (string memory);\\n\\n function symbol() external pure returns (string memory);\\n\\n function decimals() external pure returns (uint8);\\n\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address owner) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n function transferFrom(\\n address from,\\n address to,\\n uint256 value\\n ) external returns (bool);\\n\\n function DOMAIN_SEPARATOR() external view returns (bytes32);\\n\\n function PERMIT_TYPEHASH() external pure returns (bytes32);\\n\\n function nonces(address owner) external view returns (uint256);\\n\\n function permit(\\n address owner,\\n address spender,\\n uint256 value,\\n uint256 deadline,\\n uint8 v,\\n bytes32 r,\\n bytes32 s\\n ) external;\\n\\n event Mint(address indexed sender, uint256 amount0, uint256 amount1);\\n event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);\\n event Swap(\\n address indexed sender,\\n uint256 amount0In,\\n uint256 amount1In,\\n uint256 amount0Out,\\n uint256 amount1Out,\\n address indexed to\\n );\\n event Sync(uint112 reserve0, uint112 reserve1);\\n\\n function MINIMUM_LIQUIDITY() external pure returns (uint256);\\n\\n function factory() external view returns (address);\\n\\n function token0() external view returns (address);\\n\\n function token1() external view returns (address);\\n\\n function getReserves()\\n external\\n view\\n returns (\\n uint112 reserve0,\\n uint112 reserve1,\\n uint32 blockTimestampLast\\n );\\n\\n function price0CumulativeLast() external view returns (uint256);\\n\\n function price1CumulativeLast() external view returns (uint256);\\n\\n function kLast() external view returns (uint256);\\n\\n function mint(address to) external returns (uint256 liquidity);\\n\\n function burn(address to) external returns (uint256 amount0, uint256 amount1);\\n\\n function swap(\\n uint256 amount0Out,\\n uint256 amount1Out,\\n address to,\\n bytes calldata data\\n ) external;\\n\\n function skim(address to) external;\\n\\n function sync() external;\\n\\n function initialize(address, address) external;\\n}\\n\",\"keccak256\":\"0xd4d926f79ca1de45dc3f8a7e8244d62a54522cb1a3f38d881979319363ee1387\",\"license\":\"GPL-3.0\"}},\"version\":1}", + "bytecode": "0x6102006040523480156200001257600080fd5b50604051620034e0380380620034e0833981016040819052620000359162000285565b6001600160601b031960608a811b821660805289811b821660a05288811b821660c05287811b821660e05286811b82166101005285811b82166101205284811b82166101405283811b82166101605282901b16610180526040805163d21220a760e01b815290516001600160a01b038a811692908a169163d21220a791600480820192602092909190829003018186803b158015620000d357600080fd5b505afa158015620000e8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200010e91906200025f565b6001600160a01b03161415156101a081151560f81b81525050876001600160a01b0316866001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156200016b57600080fd5b505afa15801562000180573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620001a691906200025f565b6001600160a01b03161415156101c081151560f81b81525050876001600160a01b0316856001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156200020357600080fd5b505afa15801562000218573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200023e91906200025f565b6001600160a01b03161460f81b6101e0525062000374975050505050505050565b60006020828403121562000271578081fd5b81516200027e816200035b565b9392505050565b60008060008060008060008060006101208a8c031215620002a4578485fd5b8951620002b1816200035b565b60208b0151909950620002c4816200035b565b60408b0151909850620002d7816200035b565b60608b0151909750620002ea816200035b565b60808b0151909650620002fd816200035b565b60a08b015190955062000310816200035b565b60c08b015190945062000323816200035b565b60e08b015190935062000336816200035b565b6101008b01519092506200034a816200035b565b809150509295985092959850929598565b6001600160a01b03811681146200037157600080fd5b50565b60805160601c60a05160601c60c05160601c60e05160601c6101005160601c6101205160601c6101405160601c6101605160601c6101805160601c6101a05160f81c6101c05160f81c6101e05160f81c61304a62000496600039806109b8525080610a05525080610a4f5250806101f5528061053e52806105d852806108635280610ebf5280610eee5280610f8452806119f552508061023d528061040a52806104a452806106a352806107c15250806102e95280610370528061067152806106f452806107865250806107605280610aeb52508061073c528061099752508061091a52806109e45250806107185280610a2e5250806102195280610a8a5280610b1a5280611dcd52508061028f528061083d52806108d2525061304a6000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c80638a38466e11610097578063cff5dd3311610066578063cff5dd33146101b0578063d02641a0146101b8578063eee5c276146101d8578063f97a496c146101eb576100f5565b80638a38466e146101605780639bbf1deb14610168578063b985a3a014610188578063ce7a198914610190576100f5565b806335541641116100d357806335541641146101285780634e57afe014610148578063685f02e71461015057806387dabe4614610158576100f5565b80630d1dcd9a146100fa578063117be4c2146101185780632c9e2b0514610120575b600080fd5b6101026101f3565b60405161010f9190612bc4565b60405180910390f35b610102610217565b61010261023b565b61013b610136366004612543565b61025f565b60405161010f9190612eb3565b6101026106f2565b610102610716565b61010261073a565b61010261075e565b61017b610176366004612650565b610782565b60405161010f9190612d6b565b61010261083b565b6101a361019e3660046125ed565b61085f565b60405161010f9190612bf2565b610102610918565b6101cb6101c636600461250b565b61093c565b60405161010f9190612f70565b6101cb6101e636600461250b565b61096b565b6101cb61097c565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b61026761219a565b61026f61219a565b600061027961098b565b90506000670de0b6b3a76400006102b9836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b90610c41565b816102c057fe5b838552046020808501829052604080516317caf6f160e01b815290519293506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926317caf6f192600480840193919291829003018186803b15801561032d57600080fd5b505afa158015610341573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610365919061285d565b8360400181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156103c757600080fd5b505afa1580156103db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ff919061285d565b8360a00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561046157600080fd5b505afa158015610475573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610499919061285d565b8360600181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156104fb57600080fd5b505afa15801561050f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610533919061285d565b8360c00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561059557600080fd5b505afa1580156105a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105cd919061285d565b8360800181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b15801561062f57600080fd5b505afa158015610643573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610667919061285d565b60e08401526106987f0000000000000000000000000000000000000000000000000000000000000000838d8d610c78565b6101008401526106ca7f0000000000000000000000000000000000000000000000000000000000000000838b8b610c78565b6101208401526106dd8282878a8a610ea8565b61014084015250909998505050505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b031614806107f557507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b0316145b61081a5760405162461bcd60e51b815260040161081190612e12565b60405180910390fd5b600061082461098b565b905061083285828686610c78565b95945050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b0316146108b25760405162461bcd60e51b815260040161081190612dae565b60006108bc61098b565b90506000670de0b6b3a76400006108f6836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b816108fd57fe5b04905061090d8282888888610ea8565b979650505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000670de0b6b3a764000061095b61095261098b565b6102b385610a86565b8161096257fe5b0490505b919050565b600061097682610a86565b92915050565b600061098661098b565b905090565b60006003610a796109dc7f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006112b5565b610a73610a297f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006112b5565b610a737f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006112b5565b9061145a565b81610a8057fe5b04905090565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415610ad15750670de0b6b3a7640000610966565b60405163e6a4390560e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e6a4390590610b429086907f000000000000000000000000000000000000000000000000000000000000000090600401612bd8565b60206040518083038186803b158015610b5a57600080fd5b505afa158015610b6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b929190612527565b90506001600160a01b038116610bac576000915050610966565b610c3a81826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015610be957600080fd5b505afa158015610bfd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c219190612527565b6001600160a01b0316856001600160a01b0316146112b5565b9392505050565b6000811580610c5c57505080820282828281610c5957fe5b04145b6109765760405162461bcd60e51b815260040161081190612e83565b606081818167ffffffffffffffff81118015610c9357600080fd5b50604051908082528060200260200182016040528015610ccd57816020015b610cba6121f4565b815260200190600190039081610cb25790505b5090506000876001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610d0b57600080fd5b505afa158015610d1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d43919061285d565b90506000886001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610d8057600080fd5b505afa158015610d94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610db8919061285d565b905060005b84811015610e9a576000888883818110610dd357fe5b905060200201359050610de4612280565b604051631526fe2760e01b81526001600160a01b038d1690631526fe2790610e10908590600401612f70565b60806040518083038186803b158015610e2857600080fd5b505afa158015610e3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6091906126d6565b9050610e798c8c84846000015185602001518a8a61147d565b868481518110610e8557fe5b60209081029190910101525050600101610dbd565b509198975050505050505050565b6060610eb26122b1565b60405180606001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610f4557600080fd5b505afa158015610f59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f7d919061285d565b81526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610fdb57600080fd5b505afa158015610fef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611013919061285d565b905290508260608167ffffffffffffffff8111801561103157600080fd5b5060405190808252806020026020018201604052801561106b57816020015b6110586122db565b8152602001906001900390816110505790505b50905060005b828110156112a857600087878381811061108757fe5b90506020020135905061109861239f565b8551604051631526fe2760e01b81526001600160a01b0390911690631526fe27906110c7908590600401612f70565b6101206040518083038186803b1580156110e057600080fd5b505afa1580156110f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111189190612728565b90506111226123eb565b86516040516393f1a40b60e01b81526001600160a01b03909116906393f1a40b906111539086908f90600401612f79565b60606040518083038186803b15801561116b57600080fd5b505afa15801561117f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a391906127cc565b9050828585815181106111b257fe5b602090810291909101015152865185518690869081106111ce57fe5b602002602001015161012001906001600160a01b031690816001600160a01b031681525050866020015185858151811061120457fe5b6020026020010151610160018181525050866040015185858151811061122657fe5b60200260200101516101800181815250508b85858151811061124457fe5b602002602001015161020001818152505061129d8d670de0b6b3a76400006112798f8b60400151610c4190919063ffffffff16565b8161128057fe5b048d88888151811061128e57fe5b602002602001015186866117c7565b505050600101611071565b5098975050505050505050565b6000806000846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b1580156112f357600080fd5b505afa158015611307573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061132b9190612809565b506001600160701b031691506001600160701b0316915060006113c6866001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561138057600080fd5b505afa158015611394573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b89190612527565b6001600160a01b0316611c96565b60ff1690506000611409876001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561138057600080fd5b60ff16905085156114475761143c83611436866114318661142b87601261145a565b90611d57565b611d7a565b90611d96565b945050505050610976565b61143c84611436856114318561142b8860125b818101818110156109765760405162461bcd60e51b815260040161081190612d7e565b6114856121f4565b6000856001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156114c057600080fd5b505afa1580156114d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114f891906128d5565b60ff169050600061157c876001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561153b57600080fd5b505afa15801561154f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611573919061285d565b83601203611d7a565b90506000611608886001600160a01b03166370a082318d6040518263ffffffff1660e01b81526004016115af9190612bc4565b60206040518083038186803b1580156115c757600080fd5b505afa1580156115db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ff919061285d565b84601203611d7a565b90506000670de0b6b3a76400006116228c6102b38c611dc8565b8161162957fe5b0490506000896001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561166757600080fd5b505afa15801561167b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061169f9190612527565b905060008a6001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156116dc57600080fd5b505afa1580156116f0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117149190612527565b9050604051806101a001604052808d81526020018b81526020018c6001600160a01b03168152602001836001600160a01b03168152602001826001600160a01b0316815260200161176d846001600160a01b03166120c7565b8152602001611784836001600160a01b03166120c7565b81526020018481526020018681526020018f6001600160a01b031681526020018581526020018a8152602001898152509650505050505050979650505050505050565b6000826000015190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561180b57600080fd5b505afa15801561181f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118439190612527565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561188057600080fd5b505afa158015611894573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118b89190612527565b6020808701516001600160601b0316908801526001600160a01b0380851660408901528381166060890181905290821660808901529091506118f9906120c7565b60a08701526119106001600160a01b0382166120c7565b60c0870152670de0b6b3a764000061192b8a6102b386611dc8565b8161193257fe5b048660e0018181525050826001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561197557600080fd5b505afa158015611989573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119ad919061285d565b61010080880191909152850151610140870152835161022087015260c085015163ffffffff166101e0870152855160405160016232bd9d60e01b031981526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163ffcd426391611a2b91908b90600401612f79565b60006040518083038186803b158015611a4357600080fd5b505afa158015611a57573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611a7f9190810190612875565b50505061024087015250505061010082015115801590611aa3575061010083015115155b8015611ab3575061016083015115155b8015611ac2575060e083015115155b15611c8e576000836101600151611af76301e133806102b386602001516001600160601b03168a610c4190919063ffffffff16565b81611afe57fe5b0490506000846101000151611b258661014001518760e00151610c4190919063ffffffff16565b81611b2c57fe5b04905080611b3b575050611c8e565b61271081611b6c670de0b6b3a76400006102b38860c0015163ffffffff166127100387610c4190919063ffffffff16565b81611b7357fe5b0481611b7b57fe5b046101a086015260e084015115611c8b5761271081611bb9670de0b6b3a76400006102b38860c0015163ffffffff1687610c4190919063ffffffff16565b81611bc057fe5b0481611bc857fe5b046101c0860152825115801590611be25750604083015115155b15611c8b5761010084015160e0860151845160009291611c029190610c41565b81611c0957fe5b04905061271081611c49670de0b6b3a76400006102b38960e001516114368a604001516102b38d60c0015163ffffffff168c610c4190919063ffffffff16565b81611c5057fe5b0481611c5857fe5b0461026087015260e08501516040850151611c7b90670de0b6b3a7640000610c41565b81611c8257fe5b04610280870152505b50505b505050505050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b179052905160009182916060916001600160a01b03861691611cdd9190612ba8565b600060405180830381855afa9150503d8060008114611d18576040519150601f19603f3d011682016040523d82523d6000602084013e611d1d565b606091505b5091509150818015611d30575080516020145b611d3b576012611d4f565b80806020019051810190611d4f91906128d5565b949350505050565b808203828111156109765760405162461bcd60e51b815260040161081190612de5565b600081611d88575081610976565b610c3a83600a84900a610c41565b6000808211611db75760405162461bcd60e51b815260040161081190612e54565b818381611dc057fe5b049392505050565b6000807f00000000000000000000000000000000000000000000000000000000000000009050600080846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015611e2a57600080fd5b505afa158015611e3e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e629190612809565b506001600160701b031691506001600160701b031691506000856001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015611eb457600080fd5b505afa158015611ec8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611eec9190612527565b90506000866001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015611f2957600080fd5b505afa158015611f3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f619190612527565b90506000611f77836001600160a01b0316611c96565b60ff1690506000611f90836001600160a01b0316611c96565b60ff169050611fa486611431601285611d57565b9550611fb585611431601284611d57565b9450600080886001600160a01b0316866001600160a01b03161415611ff157670de0b6b3a76400009150611fea8b60016112b5565b9050612090565b886001600160a01b0316856001600160a01b03161415612028576120168b60006112b5565b9150670de0b6b3a76400009050612090565b61203186610a86565b915061203c85610a86565b90508161207357670de0b6b3a764000061205b60026102b38a85610c41565b8161206257fe5b049950505050505050505050610966565b8061209057670de0b6b3a764000061205b60026102b38b86610c41565b670de0b6b3a76400006120b06120a68984610c41565b610a738b86610c41565b816120b757fe5b049b9a5050505050505050505050565b60408051600481526024810182526020810180516001600160e01b03166395d89b4160e01b179052905160609160009183916001600160a01b0386169161210e9190612ba8565b600060405180830381855afa9150503d8060008114612149576040519150601f19603f3d011682016040523d82523d6000602084013e61214e565b606091505b5091509150818015612161575060008151115b61218657604051806040016040528060038152602001623f3f3f60e81b815250611d4f565b80806020019051810190611d4f91906126a3565b60405180610160016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016060815260200160608152602001606081525090565b604051806101a00160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806080016040528060006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b604051806102a00160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915290565b60405180606001604052806000815260200160008152602001600081525090565b805161097681612fe7565b60008083601f840112612428578182fd5b50813567ffffffffffffffff81111561243f578182fd5b602083019150836020808302850101111561245957600080fd5b9250929050565b600082601f830112612470578081fd5b815167ffffffffffffffff811115612486578182fd5b612499601f8201601f1916602001612f90565b91508082528360208285010111156124b057600080fd5b6124c1816020840160208601612fb7565b5092915050565b805163ffffffff8116811461097657600080fd5b805167ffffffffffffffff8116811461097657600080fd5b80516001600160601b038116811461097657600080fd5b60006020828403121561251c578081fd5b8135610c3a81612fe7565b600060208284031215612538578081fd5b8151610c3a81612fe7565b60008060008060008060006080888a03121561255d578283fd5b873567ffffffffffffffff80821115612574578485fd5b6125808b838c01612417565b909950975060208a0135915080821115612598578485fd5b6125a48b838c01612417565b909750955060408a01359150808211156125bc578485fd5b506125c98a828b01612417565b90945092505060608801356125dd81612fe7565b8091505092959891949750929550565b60008060008060608587031215612602578384fd5b843561260d81612fe7565b9350602085013561261d81612fe7565b9250604085013567ffffffffffffffff811115612638578283fd5b61264487828801612417565b95989497509550505050565b600080600060408486031215612664578283fd5b833561266f81612fe7565b9250602084013567ffffffffffffffff81111561268a578283fd5b61269686828701612417565b9497909650939450505050565b6000602082840312156126b4578081fd5b815167ffffffffffffffff8111156126ca578182fd5b611d4f84828501612460565b6000608082840312156126e7578081fd5b6126f16080612f90565b82516126fc81612fe7565b808252506020830151602082015260408301516040820152606083015160608201528091505092915050565b600061012080838503121561273b578182fd5b61274481612f90565b9050612750848461240c565b815261275f84602085016124f4565b6020820152604083015160408201526060830151606082015261278584608085016124dc565b60808201526127978460a0850161240c565b60a08201526127a98460c085016124c8565b60c082015260e08381015190820152610100928301519281019290925250919050565b6000606082840312156127dd578081fd5b6127e76060612f90565b8251815260208301516020820152604083015160408201528091505092915050565b60008060006060848603121561281d578081fd5b835161282881612fff565b602085015190935061283981612fff565b604085015190925063ffffffff81168114612852578182fd5b809150509250925092565b60006020828403121561286e578081fd5b5051919050565b6000806000806080858703121561288a578182fd5b84519350602085015161289c81612fe7565b604086015190935067ffffffffffffffff8111156128b8578283fd5b6128c487828801612460565b606096909601519497939650505050565b6000602082840312156128e6578081fd5b815160ff81168114610c3a578182fd5b6001600160a01b03169052565b6000815180845260208085018081965082840281019150828601855b85811015612a6557828403895281516102a081518652868201518787015260408083015161294f828901826128f6565b5050606080830151612963828901826128f6565b5050608080830151612977828901826128f6565b505060a080830151828289015261299083890182612b7c565b9250505060c080830151878303828901526129ab8382612b7c565b9250505060e0808301518188015250610100808301518188015250610120808301516129d9828901826128f6565b50506101408281015190870152610160808301519087015261018080830151908701526101a080830151908701526101c080830151908701526101e080830151908701526102008083015190870152610220808301519087015261024080830151908701526102608083015190870152610280918201519190950152978401979084019060010161291f565b5091979650505050505050565b6000815180845260208085018081965082840281019150828601855b85811015612a6557828403895281516101a0815186528682015187870152604080830151612abe828901826128f6565b5050606080830151612ad2828901826128f6565b5050608080830151612ae6828901826128f6565b505060a0808301518282890152612aff83890182612b7c565b9250505060c08083015187830382890152612b1a8382612b7c565b9250505060e080830151818801525061010080830151818801525061012080830151612b48828901826128f6565b5050610140828101519087015261016080830151908701526101809182015191909501529784019790840190600101612a8e565b60008151808452612b94816020860160208601612fb7565b601f01601f19169290920160200192915050565b60008251612bba818460208701612fb7565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b60208082528251828201819052600091906040908185019080840286018301878501865b83811015612d5d57603f1989840301855281516102a081518552888201518986015287820151612c48898701826128f6565b50606080830151612c5b828801826128f6565b5050608080830151612c6f828801826128f6565b505060a0808301518282880152612c8883880182612b7c565b9250505060c08083015186830382880152612ca38382612b7c565b9250505060e080830151818701525061010080830151818701525061012080830151612cd1828801826128f6565b50506101408281015190860152610160808301519086015261018080830151908601526101a080830151908601526101c080830151908601526101e0808301519086015261020080830151908601526102208083015190860152610240808301519086015261026080830151908601526102809182015191909401529386019390860190600101612c16565b509098975050505050505050565b600060208252610c3a6020830184612a72565b602080825260169082015275536166654d6174683a20416464204f766572666c6f7760501b604082015260600190565b60208082526019908201527f4661726d4c656e7356323a204f6e6c7920666f7220424d434a00000000000000604082015260600190565b602080825260139082015272536166654d6174683a20556e646572666c6f7760681b604082015260600190565b60208082526022908201527f4661726d4c656e7356323a206f6e6c7920666f72204d43563220616e64204d43604082015261563360f01b606082015260800190565b602080825260159082015274536166654d6174683a20446976206279205a65726f60581b604082015260600190565b602080825260169082015275536166654d6174683a204d756c204f766572666c6f7760501b604082015260600190565b60006020825282516020830152602083015160408301526040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015160e083015260e08301516101008181850152808501519150506101606101208181860152612f29610180860184612a72565b9250808601519050601f19610140818786030181880152612f4a8584612a72565b908801518782039092018488015293509050612f668382612903565b9695505050505050565b90815260200190565b9182526001600160a01b0316602082015260400190565b60405181810167ffffffffffffffff81118282101715612faf57600080fd5b604052919050565b60005b83811015612fd2578181015183820152602001612fba565b83811115612fe1576000848401525b50505050565b6001600160a01b0381168114612ffc57600080fd5b50565b6001600160701b0381168114612ffc57600080fdfea26469706673582212203983aa55900a9760eadb8c17e41a9090e6945d3e4e8842df70b5c141f517dd2c64736f6c634300060c0033", + "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100f55760003560e01c80638a38466e11610097578063cff5dd3311610066578063cff5dd33146101b0578063d02641a0146101b8578063eee5c276146101d8578063f97a496c146101eb576100f5565b80638a38466e146101605780639bbf1deb14610168578063b985a3a014610188578063ce7a198914610190576100f5565b806335541641116100d357806335541641146101285780634e57afe014610148578063685f02e71461015057806387dabe4614610158576100f5565b80630d1dcd9a146100fa578063117be4c2146101185780632c9e2b0514610120575b600080fd5b6101026101f3565b60405161010f9190612bc4565b60405180910390f35b610102610217565b61010261023b565b61013b610136366004612543565b61025f565b60405161010f9190612eb3565b6101026106f2565b610102610716565b61010261073a565b61010261075e565b61017b610176366004612650565b610782565b60405161010f9190612d6b565b61010261083b565b6101a361019e3660046125ed565b61085f565b60405161010f9190612bf2565b610102610918565b6101cb6101c636600461250b565b61093c565b60405161010f9190612f70565b6101cb6101e636600461250b565b61096b565b6101cb61097c565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b61026761219a565b61026f61219a565b600061027961098b565b90506000670de0b6b3a76400006102b9836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b90610c41565b816102c057fe5b838552046020808501829052604080516317caf6f160e01b815290519293506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926317caf6f192600480840193919291829003018186803b15801561032d57600080fd5b505afa158015610341573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610365919061285d565b8360400181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156103c757600080fd5b505afa1580156103db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ff919061285d565b8360a00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561046157600080fd5b505afa158015610475573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610499919061285d565b8360600181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156104fb57600080fd5b505afa15801561050f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610533919061285d565b8360c00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561059557600080fd5b505afa1580156105a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105cd919061285d565b8360800181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b15801561062f57600080fd5b505afa158015610643573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610667919061285d565b60e08401526106987f0000000000000000000000000000000000000000000000000000000000000000838d8d610c78565b6101008401526106ca7f0000000000000000000000000000000000000000000000000000000000000000838b8b610c78565b6101208401526106dd8282878a8a610ea8565b61014084015250909998505050505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b031614806107f557507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b0316145b61081a5760405162461bcd60e51b815260040161081190612e12565b60405180910390fd5b600061082461098b565b905061083285828686610c78565b95945050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b0316146108b25760405162461bcd60e51b815260040161081190612dae565b60006108bc61098b565b90506000670de0b6b3a76400006108f6836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b816108fd57fe5b04905061090d8282888888610ea8565b979650505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000670de0b6b3a764000061095b61095261098b565b6102b385610a86565b8161096257fe5b0490505b919050565b600061097682610a86565b92915050565b600061098661098b565b905090565b60006003610a796109dc7f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006112b5565b610a73610a297f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006112b5565b610a737f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006112b5565b9061145a565b81610a8057fe5b04905090565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415610ad15750670de0b6b3a7640000610966565b60405163e6a4390560e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e6a4390590610b429086907f000000000000000000000000000000000000000000000000000000000000000090600401612bd8565b60206040518083038186803b158015610b5a57600080fd5b505afa158015610b6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b929190612527565b90506001600160a01b038116610bac576000915050610966565b610c3a81826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015610be957600080fd5b505afa158015610bfd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c219190612527565b6001600160a01b0316856001600160a01b0316146112b5565b9392505050565b6000811580610c5c57505080820282828281610c5957fe5b04145b6109765760405162461bcd60e51b815260040161081190612e83565b606081818167ffffffffffffffff81118015610c9357600080fd5b50604051908082528060200260200182016040528015610ccd57816020015b610cba6121f4565b815260200190600190039081610cb25790505b5090506000876001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610d0b57600080fd5b505afa158015610d1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d43919061285d565b90506000886001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610d8057600080fd5b505afa158015610d94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610db8919061285d565b905060005b84811015610e9a576000888883818110610dd357fe5b905060200201359050610de4612280565b604051631526fe2760e01b81526001600160a01b038d1690631526fe2790610e10908590600401612f70565b60806040518083038186803b158015610e2857600080fd5b505afa158015610e3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6091906126d6565b9050610e798c8c84846000015185602001518a8a61147d565b868481518110610e8557fe5b60209081029190910101525050600101610dbd565b509198975050505050505050565b6060610eb26122b1565b60405180606001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610f4557600080fd5b505afa158015610f59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f7d919061285d565b81526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610fdb57600080fd5b505afa158015610fef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611013919061285d565b905290508260608167ffffffffffffffff8111801561103157600080fd5b5060405190808252806020026020018201604052801561106b57816020015b6110586122db565b8152602001906001900390816110505790505b50905060005b828110156112a857600087878381811061108757fe5b90506020020135905061109861239f565b8551604051631526fe2760e01b81526001600160a01b0390911690631526fe27906110c7908590600401612f70565b6101206040518083038186803b1580156110e057600080fd5b505afa1580156110f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111189190612728565b90506111226123eb565b86516040516393f1a40b60e01b81526001600160a01b03909116906393f1a40b906111539086908f90600401612f79565b60606040518083038186803b15801561116b57600080fd5b505afa15801561117f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a391906127cc565b9050828585815181106111b257fe5b602090810291909101015152865185518690869081106111ce57fe5b602002602001015161012001906001600160a01b031690816001600160a01b031681525050866020015185858151811061120457fe5b6020026020010151610160018181525050866040015185858151811061122657fe5b60200260200101516101800181815250508b85858151811061124457fe5b602002602001015161020001818152505061129d8d670de0b6b3a76400006112798f8b60400151610c4190919063ffffffff16565b8161128057fe5b048d88888151811061128e57fe5b602002602001015186866117c7565b505050600101611071565b5098975050505050505050565b6000806000846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b1580156112f357600080fd5b505afa158015611307573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061132b9190612809565b506001600160701b031691506001600160701b0316915060006113c6866001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561138057600080fd5b505afa158015611394573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b89190612527565b6001600160a01b0316611c96565b60ff1690506000611409876001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561138057600080fd5b60ff16905085156114475761143c83611436866114318661142b87601261145a565b90611d57565b611d7a565b90611d96565b945050505050610976565b61143c84611436856114318561142b8860125b818101818110156109765760405162461bcd60e51b815260040161081190612d7e565b6114856121f4565b6000856001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156114c057600080fd5b505afa1580156114d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114f891906128d5565b60ff169050600061157c876001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561153b57600080fd5b505afa15801561154f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611573919061285d565b83601203611d7a565b90506000611608886001600160a01b03166370a082318d6040518263ffffffff1660e01b81526004016115af9190612bc4565b60206040518083038186803b1580156115c757600080fd5b505afa1580156115db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ff919061285d565b84601203611d7a565b90506000670de0b6b3a76400006116228c6102b38c611dc8565b8161162957fe5b0490506000896001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561166757600080fd5b505afa15801561167b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061169f9190612527565b905060008a6001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156116dc57600080fd5b505afa1580156116f0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117149190612527565b9050604051806101a001604052808d81526020018b81526020018c6001600160a01b03168152602001836001600160a01b03168152602001826001600160a01b0316815260200161176d846001600160a01b03166120c7565b8152602001611784836001600160a01b03166120c7565b81526020018481526020018681526020018f6001600160a01b031681526020018581526020018a8152602001898152509650505050505050979650505050505050565b6000826000015190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561180b57600080fd5b505afa15801561181f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118439190612527565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561188057600080fd5b505afa158015611894573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118b89190612527565b6020808701516001600160601b0316908801526001600160a01b0380851660408901528381166060890181905290821660808901529091506118f9906120c7565b60a08701526119106001600160a01b0382166120c7565b60c0870152670de0b6b3a764000061192b8a6102b386611dc8565b8161193257fe5b048660e0018181525050826001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561197557600080fd5b505afa158015611989573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119ad919061285d565b61010080880191909152850151610140870152835161022087015260c085015163ffffffff166101e0870152855160405160016232bd9d60e01b031981526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163ffcd426391611a2b91908b90600401612f79565b60006040518083038186803b158015611a4357600080fd5b505afa158015611a57573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611a7f9190810190612875565b50505061024087015250505061010082015115801590611aa3575061010083015115155b8015611ab3575061016083015115155b8015611ac2575060e083015115155b15611c8e576000836101600151611af76301e133806102b386602001516001600160601b03168a610c4190919063ffffffff16565b81611afe57fe5b0490506000846101000151611b258661014001518760e00151610c4190919063ffffffff16565b81611b2c57fe5b04905080611b3b575050611c8e565b61271081611b6c670de0b6b3a76400006102b38860c0015163ffffffff166127100387610c4190919063ffffffff16565b81611b7357fe5b0481611b7b57fe5b046101a086015260e084015115611c8b5761271081611bb9670de0b6b3a76400006102b38860c0015163ffffffff1687610c4190919063ffffffff16565b81611bc057fe5b0481611bc857fe5b046101c0860152825115801590611be25750604083015115155b15611c8b5761010084015160e0860151845160009291611c029190610c41565b81611c0957fe5b04905061271081611c49670de0b6b3a76400006102b38960e001516114368a604001516102b38d60c0015163ffffffff168c610c4190919063ffffffff16565b81611c5057fe5b0481611c5857fe5b0461026087015260e08501516040850151611c7b90670de0b6b3a7640000610c41565b81611c8257fe5b04610280870152505b50505b505050505050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b179052905160009182916060916001600160a01b03861691611cdd9190612ba8565b600060405180830381855afa9150503d8060008114611d18576040519150601f19603f3d011682016040523d82523d6000602084013e611d1d565b606091505b5091509150818015611d30575080516020145b611d3b576012611d4f565b80806020019051810190611d4f91906128d5565b949350505050565b808203828111156109765760405162461bcd60e51b815260040161081190612de5565b600081611d88575081610976565b610c3a83600a84900a610c41565b6000808211611db75760405162461bcd60e51b815260040161081190612e54565b818381611dc057fe5b049392505050565b6000807f00000000000000000000000000000000000000000000000000000000000000009050600080846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015611e2a57600080fd5b505afa158015611e3e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e629190612809565b506001600160701b031691506001600160701b031691506000856001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015611eb457600080fd5b505afa158015611ec8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611eec9190612527565b90506000866001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015611f2957600080fd5b505afa158015611f3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f619190612527565b90506000611f77836001600160a01b0316611c96565b60ff1690506000611f90836001600160a01b0316611c96565b60ff169050611fa486611431601285611d57565b9550611fb585611431601284611d57565b9450600080886001600160a01b0316866001600160a01b03161415611ff157670de0b6b3a76400009150611fea8b60016112b5565b9050612090565b886001600160a01b0316856001600160a01b03161415612028576120168b60006112b5565b9150670de0b6b3a76400009050612090565b61203186610a86565b915061203c85610a86565b90508161207357670de0b6b3a764000061205b60026102b38a85610c41565b8161206257fe5b049950505050505050505050610966565b8061209057670de0b6b3a764000061205b60026102b38b86610c41565b670de0b6b3a76400006120b06120a68984610c41565b610a738b86610c41565b816120b757fe5b049b9a5050505050505050505050565b60408051600481526024810182526020810180516001600160e01b03166395d89b4160e01b179052905160609160009183916001600160a01b0386169161210e9190612ba8565b600060405180830381855afa9150503d8060008114612149576040519150601f19603f3d011682016040523d82523d6000602084013e61214e565b606091505b5091509150818015612161575060008151115b61218657604051806040016040528060038152602001623f3f3f60e81b815250611d4f565b80806020019051810190611d4f91906126a3565b60405180610160016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016060815260200160608152602001606081525090565b604051806101a00160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806080016040528060006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b604051806102a00160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915290565b60405180606001604052806000815260200160008152602001600081525090565b805161097681612fe7565b60008083601f840112612428578182fd5b50813567ffffffffffffffff81111561243f578182fd5b602083019150836020808302850101111561245957600080fd5b9250929050565b600082601f830112612470578081fd5b815167ffffffffffffffff811115612486578182fd5b612499601f8201601f1916602001612f90565b91508082528360208285010111156124b057600080fd5b6124c1816020840160208601612fb7565b5092915050565b805163ffffffff8116811461097657600080fd5b805167ffffffffffffffff8116811461097657600080fd5b80516001600160601b038116811461097657600080fd5b60006020828403121561251c578081fd5b8135610c3a81612fe7565b600060208284031215612538578081fd5b8151610c3a81612fe7565b60008060008060008060006080888a03121561255d578283fd5b873567ffffffffffffffff80821115612574578485fd5b6125808b838c01612417565b909950975060208a0135915080821115612598578485fd5b6125a48b838c01612417565b909750955060408a01359150808211156125bc578485fd5b506125c98a828b01612417565b90945092505060608801356125dd81612fe7565b8091505092959891949750929550565b60008060008060608587031215612602578384fd5b843561260d81612fe7565b9350602085013561261d81612fe7565b9250604085013567ffffffffffffffff811115612638578283fd5b61264487828801612417565b95989497509550505050565b600080600060408486031215612664578283fd5b833561266f81612fe7565b9250602084013567ffffffffffffffff81111561268a578283fd5b61269686828701612417565b9497909650939450505050565b6000602082840312156126b4578081fd5b815167ffffffffffffffff8111156126ca578182fd5b611d4f84828501612460565b6000608082840312156126e7578081fd5b6126f16080612f90565b82516126fc81612fe7565b808252506020830151602082015260408301516040820152606083015160608201528091505092915050565b600061012080838503121561273b578182fd5b61274481612f90565b9050612750848461240c565b815261275f84602085016124f4565b6020820152604083015160408201526060830151606082015261278584608085016124dc565b60808201526127978460a0850161240c565b60a08201526127a98460c085016124c8565b60c082015260e08381015190820152610100928301519281019290925250919050565b6000606082840312156127dd578081fd5b6127e76060612f90565b8251815260208301516020820152604083015160408201528091505092915050565b60008060006060848603121561281d578081fd5b835161282881612fff565b602085015190935061283981612fff565b604085015190925063ffffffff81168114612852578182fd5b809150509250925092565b60006020828403121561286e578081fd5b5051919050565b6000806000806080858703121561288a578182fd5b84519350602085015161289c81612fe7565b604086015190935067ffffffffffffffff8111156128b8578283fd5b6128c487828801612460565b606096909601519497939650505050565b6000602082840312156128e6578081fd5b815160ff81168114610c3a578182fd5b6001600160a01b03169052565b6000815180845260208085018081965082840281019150828601855b85811015612a6557828403895281516102a081518652868201518787015260408083015161294f828901826128f6565b5050606080830151612963828901826128f6565b5050608080830151612977828901826128f6565b505060a080830151828289015261299083890182612b7c565b9250505060c080830151878303828901526129ab8382612b7c565b9250505060e0808301518188015250610100808301518188015250610120808301516129d9828901826128f6565b50506101408281015190870152610160808301519087015261018080830151908701526101a080830151908701526101c080830151908701526101e080830151908701526102008083015190870152610220808301519087015261024080830151908701526102608083015190870152610280918201519190950152978401979084019060010161291f565b5091979650505050505050565b6000815180845260208085018081965082840281019150828601855b85811015612a6557828403895281516101a0815186528682015187870152604080830151612abe828901826128f6565b5050606080830151612ad2828901826128f6565b5050608080830151612ae6828901826128f6565b505060a0808301518282890152612aff83890182612b7c565b9250505060c08083015187830382890152612b1a8382612b7c565b9250505060e080830151818801525061010080830151818801525061012080830151612b48828901826128f6565b5050610140828101519087015261016080830151908701526101809182015191909501529784019790840190600101612a8e565b60008151808452612b94816020860160208601612fb7565b601f01601f19169290920160200192915050565b60008251612bba818460208701612fb7565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b60208082528251828201819052600091906040908185019080840286018301878501865b83811015612d5d57603f1989840301855281516102a081518552888201518986015287820151612c48898701826128f6565b50606080830151612c5b828801826128f6565b5050608080830151612c6f828801826128f6565b505060a0808301518282880152612c8883880182612b7c565b9250505060c08083015186830382880152612ca38382612b7c565b9250505060e080830151818701525061010080830151818701525061012080830151612cd1828801826128f6565b50506101408281015190860152610160808301519086015261018080830151908601526101a080830151908601526101c080830151908601526101e0808301519086015261020080830151908601526102208083015190860152610240808301519086015261026080830151908601526102809182015191909401529386019390860190600101612c16565b509098975050505050505050565b600060208252610c3a6020830184612a72565b602080825260169082015275536166654d6174683a20416464204f766572666c6f7760501b604082015260600190565b60208082526019908201527f4661726d4c656e7356323a204f6e6c7920666f7220424d434a00000000000000604082015260600190565b602080825260139082015272536166654d6174683a20556e646572666c6f7760681b604082015260600190565b60208082526022908201527f4661726d4c656e7356323a206f6e6c7920666f72204d43563220616e64204d43604082015261563360f01b606082015260800190565b602080825260159082015274536166654d6174683a20446976206279205a65726f60581b604082015260600190565b602080825260169082015275536166654d6174683a204d756c204f766572666c6f7760501b604082015260600190565b60006020825282516020830152602083015160408301526040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015160e083015260e08301516101008181850152808501519150506101606101208181860152612f29610180860184612a72565b9250808601519050601f19610140818786030181880152612f4a8584612a72565b908801518782039092018488015293509050612f668382612903565b9695505050505050565b90815260200190565b9182526001600160a01b0316602082015260400190565b60405181810167ffffffffffffffff81118282101715612faf57600080fd5b604052919050565b60005b83811015612fd2578181015183820152602001612fba565b83811115612fe1576000848401525b50505050565b6001600160a01b0381168114612ffc57600080fd5b50565b6001600160701b0381168114612ffc57600080fdfea26469706673582212203983aa55900a9760eadb8c17e41a9090e6945d3e4e8842df70b5c141f517dd2c64736f6c634300060c0033", "devdoc": { "kind": "dev", "methods": { diff --git a/deployments/avalanche/solcInputs/05be5b065453cde7967331fef060caff.json b/deployments/avalanche/solcInputs/05be5b065453cde7967331fef060caff.json new file mode 100644 index 00000000..40b2e0aa --- /dev/null +++ b/deployments/avalanche/solcInputs/05be5b065453cde7967331fef060caff.json @@ -0,0 +1,274 @@ +{ + "language": "Solidity", + "sources": { + "contracts/BoostedMasterChefJoe.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/proxy/Initializable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol\";\nimport \"./interfaces/IERC20.sol\";\nimport \"./interfaces/IMasterChefJoe.sol\";\nimport \"./interfaces/IRewarder.sol\";\nimport \"./libraries/BoringJoeERC20.sol\";\nimport \"./traderjoe/libraries/Math.sol\";\n\n/// @notice The (older) MasterChefJoeV2 contract gives out a constant number of JOE\n/// tokens per block. It is the only address with minting rights for JOE. The idea\n/// for this BoostedMasterChefJoe (BMCJ) contract is therefore to be the owner of a\n/// dummy token that is deposited into the MasterChefJoeV2 (MCJV2) contract. The\n/// allocation point for this pool on MCJV2 is the total allocation point for all\n/// pools on BMCJ.\n///\n/// This MasterChef also skews how many rewards users receive, it does this by\n/// modifying the algorithm that calculates how many tokens are rewarded to\n/// depositors. Whereas MasterChef calculates rewards based on emission rate and\n/// total liquidity, this version uses adjusted parameters to this calculation.\n///\n/// A users `boostedAmount` (liquidity multiplier) is calculated by the actual supplied\n/// liquidity multiplied by a boost factor. The boost factor is calculated by the\n/// amount of veJOE held by the user over the total veJOE amount held by all pool\n/// participants. Total liquidity is the sum of all boosted liquidity.\ncontract BoostedMasterChefJoe is Initializable, OwnableUpgradeable, ReentrancyGuardUpgradeable {\n using BoringJoeERC20 for IERC20;\n using SafeMathUpgradeable for uint256;\n\n /// @notice Info of each BMCJ user\n /// `amount` LP token amount the user has provided\n /// `rewardDebt` The amount of JOE entitled to the user\n /// `factor` the users factor, use _getUserFactor\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n uint256 factor;\n }\n\n /// @notice Info of each BMCJ pool\n /// `allocPoint` The amount of allocation points assigned to the pool\n /// Also known as the amount of JOE to distribute per block\n struct PoolInfo {\n // Address are stored in 160 bits, so we store allocPoint in 96 bits to\n // optimize storage (160 + 96 = 256)\n IERC20 lpToken;\n uint96 allocPoint;\n uint256 accJoePerShare;\n uint256 accJoePerFactorPerShare;\n // Address are stored in 160 bits, so we store lastRewardTimestamp in 64 bits and\n // veJoeShareBp in 32 bits to optimize storage (160 + 64 + 32 = 256)\n uint64 lastRewardTimestamp;\n IRewarder rewarder;\n // Share of the reward to distribute to veJoe holders\n uint32 veJoeShareBp;\n // The sum of all veJoe held by users participating in this farm\n // This value is updated when\n // - A user enter/leaves a farm\n // - A user claims veJOE\n // - A user unstakes JOE\n uint256 totalFactor;\n // The total LP supply of the farm\n // This is the sum of all users boosted amounts in the farm. Updated when\n // someone deposits or withdraws.\n // This is used instead of the usual `lpToken.balanceOf(address(this))` for security reasons\n uint256 totalLpSupply;\n }\n\n /// @notice Address of MCJV2 contract\n IMasterChefJoe public MASTER_CHEF_V2;\n /// @notice Address of JOE contract\n IERC20 public JOE;\n /// @notice Address of veJOE contract\n IERC20 public VEJOE;\n /// @notice The index of BMCJ master pool in MCJV2\n uint256 public MASTER_PID;\n\n /// @notice Info of each BMCJ pool\n PoolInfo[] public poolInfo;\n /// @dev Maps an address to a bool to assert that a token isn't added twice\n mapping(IERC20 => bool) private checkPoolDuplicate;\n\n /// @notice Info of each user that stakes LP tokens\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n /// @dev Total allocation points. Must be the sum of all allocation points in all pools\n uint256 public totalAllocPoint;\n uint256 private ACC_TOKEN_PRECISION;\n\n /// @dev Amount of claimable Joe the user has, this is required as we\n /// need to update rewardDebt after a token operation but we don't\n /// want to send a reward at this point. This amount gets added onto\n /// the pending amount when a user claims\n mapping(uint256 => mapping(address => uint256)) public claimableJoe;\n\n event Add(\n uint256 indexed pid,\n uint256 allocPoint,\n uint256 veJoeShareBp,\n IERC20 indexed lpToken,\n IRewarder indexed rewarder\n );\n event Set(\n uint256 indexed pid,\n uint256 allocPoint,\n uint256 veJoeShareBp,\n IRewarder indexed rewarder,\n bool overwrite\n );\n event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\n event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event UpdatePool(\n uint256 indexed pid,\n uint256 lastRewardTimestamp,\n uint256 lpSupply,\n uint256 accJoePerShare,\n uint256 accJoePerFactorPerShare\n );\n event Harvest(address indexed user, uint256 indexed pid, uint256 amount);\n event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event Init(uint256 amount);\n\n /// @param _MASTER_CHEF_V2 The MCJV2 contract address\n /// @param _joe The JOE token contract address\n /// @param _veJoe The veJOE token contract address\n /// @param _MASTER_PID The pool ID of the dummy token on the base MCJV2 contract\n function initialize(\n IMasterChefJoe _MASTER_CHEF_V2,\n IERC20 _joe,\n IERC20 _veJoe,\n uint256 _MASTER_PID\n ) public initializer {\n __Ownable_init();\n MASTER_CHEF_V2 = _MASTER_CHEF_V2;\n JOE = _joe;\n VEJOE = _veJoe;\n MASTER_PID = _MASTER_PID;\n\n ACC_TOKEN_PRECISION = 1e18;\n }\n\n /// @notice Deposits a dummy token to `MASTER_CHEF_V2` MCJV2. This is required because MCJV2\n /// holds the minting rights for JOE. Any balance of transaction sender in `_dummyToken` is transferred.\n /// The allocation point for the pool on MCJV2 is the total allocation point for all pools that receive\n /// double incentives.\n /// @param _dummyToken The address of the ERC-20 token to deposit into MCJV2.\n function init(IERC20 _dummyToken) external onlyOwner {\n require(\n _dummyToken.balanceOf(address(MASTER_CHEF_V2)) == 0,\n \"BoostedMasterChefJoe: Already has a balance of dummy token\"\n );\n uint256 balance = _dummyToken.balanceOf(_msgSender());\n require(balance != 0, \"BoostedMasterChefJoe: Balance must exceed 0\");\n _dummyToken.safeTransferFrom(_msgSender(), address(this), balance);\n _dummyToken.approve(address(MASTER_CHEF_V2), balance);\n MASTER_CHEF_V2.deposit(MASTER_PID, balance);\n emit Init(balance);\n }\n\n /// @notice Add a new LP to the pool. Can only be called by the owner.\n /// @param _allocPoint AP of the new pool.\n /// @param _veJoeShareBp Share of rewards allocated in proportion to user's liquidity\n /// and veJoe balance\n /// @param _lpToken Address of the LP ERC-20 token.\n /// @param _rewarder Address of the rewarder delegate.\n function add(\n uint96 _allocPoint,\n uint32 _veJoeShareBp,\n IERC20 _lpToken,\n IRewarder _rewarder\n ) external onlyOwner {\n require(!checkPoolDuplicate[_lpToken], \"BoostedMasterChefJoe: LP already added\");\n require(_veJoeShareBp <= 10_000, \"BoostedMasterChefJoe: veJoeShareBp needs to be lower than 10000\");\n require(poolInfo.length <= 50, \"BoostedMasterChefJoe: Too many pools\");\n checkPoolDuplicate[_lpToken] = true;\n // Sanity check to ensure _lpToken is an ERC20 token\n _lpToken.balanceOf(address(this));\n // Sanity check if we add a rewarder\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(address(0), 0);\n }\n\n massUpdatePools();\n\n totalAllocPoint = totalAllocPoint.add(_allocPoint);\n\n poolInfo.push(\n PoolInfo({\n lpToken: _lpToken,\n allocPoint: _allocPoint,\n accJoePerShare: 0,\n accJoePerFactorPerShare: 0,\n lastRewardTimestamp: uint64(block.timestamp),\n rewarder: _rewarder,\n veJoeShareBp: _veJoeShareBp,\n totalFactor: 0,\n totalLpSupply: 0\n })\n );\n emit Add(poolInfo.length - 1, _allocPoint, _veJoeShareBp, _lpToken, _rewarder);\n }\n\n /// @notice Update the given pool's JOE allocation point and `IRewarder` contract. Can only be called by the owner.\n /// @param _pid The index of the pool. See `poolInfo`\n /// @param _allocPoint New AP of the pool\n /// @param _veJoeShareBp Share of rewards allocated in proportion to user's liquidity\n /// and veJoe balance\n /// @param _rewarder Address of the rewarder delegate\n /// @param _overwrite True if _rewarder should be `set`. Otherwise `_rewarder` is ignored\n function set(\n uint256 _pid,\n uint96 _allocPoint,\n uint32 _veJoeShareBp,\n IRewarder _rewarder,\n bool _overwrite\n ) external onlyOwner {\n require(_veJoeShareBp <= 10_000, \"BoostedMasterChefJoe: veJoeShareBp needs to be lower than 10000\");\n massUpdatePools();\n\n PoolInfo storage pool = poolInfo[_pid];\n totalAllocPoint = totalAllocPoint.add(_allocPoint).sub(pool.allocPoint);\n pool.allocPoint = _allocPoint;\n pool.veJoeShareBp = _veJoeShareBp;\n if (_overwrite) {\n if (address(_rewarder) != address(0)) {\n // Sanity check\n _rewarder.onJoeReward(address(0), 0);\n }\n pool.rewarder = _rewarder;\n }\n\n emit Set(_pid, _allocPoint, _veJoeShareBp, _overwrite ? _rewarder : pool.rewarder, _overwrite);\n }\n\n /// @notice Deposit LP tokens to BMCJ for JOE allocation\n /// @param _pid The index of the pool. See `poolInfo`\n /// @param _amount LP token amount to deposit\n function deposit(uint256 _pid, uint256 _amount) external nonReentrant {\n harvestFromMasterChef();\n updatePool(_pid);\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_msgSender()];\n\n // Pay a user any pending rewards\n if (user.amount != 0) {\n _harvestJoe(user, pool, _pid);\n }\n\n uint256 balanceBefore = pool.lpToken.balanceOf(address(this));\n pool.lpToken.safeTransferFrom(_msgSender(), address(this), _amount);\n uint256 receivedAmount = pool.lpToken.balanceOf(address(this)).sub(balanceBefore);\n\n _updateUserAndPool(user, pool, receivedAmount, true);\n\n IRewarder _rewarder = pool.rewarder;\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(_msgSender(), user.amount);\n }\n emit Deposit(_msgSender(), _pid, receivedAmount);\n }\n\n /// @notice Withdraw LP tokens from BMCJ\n /// @param _pid The index of the pool. See `poolInfo`\n /// @param _amount LP token amount to withdraw\n function withdraw(uint256 _pid, uint256 _amount) external nonReentrant {\n harvestFromMasterChef();\n updatePool(_pid);\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_msgSender()];\n require(user.amount >= _amount, \"BoostedMasterChefJoe: withdraw not good\");\n\n if (user.amount != 0) {\n _harvestJoe(user, pool, _pid);\n }\n\n _updateUserAndPool(user, pool, _amount, false);\n\n pool.lpToken.safeTransfer(_msgSender(), _amount);\n\n IRewarder _rewarder = pool.rewarder;\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(_msgSender(), user.amount);\n }\n emit Withdraw(_msgSender(), _pid, _amount);\n }\n\n /// @notice Updates factor after after a veJoe token operation.\n /// This function needs to be called by the veJoe contract after\n /// every mint / burn.\n /// @param _user The users address we are updating\n /// @param _newVeJoeBalance The new balance of the users veJoe\n function updateFactor(address _user, uint256 _newVeJoeBalance) external {\n require(_msgSender() == address(VEJOE), \"BoostedMasterChefJoe: Caller not veJOE\");\n uint256 len = poolInfo.length;\n uint256 _ACC_TOKEN_PRECISION = ACC_TOKEN_PRECISION;\n\n for (uint256 pid; pid < len; ++pid) {\n UserInfo storage user = userInfo[pid][_user];\n\n // Skip if user doesn't have any deposit in the pool\n uint256 amount = user.amount;\n if (amount == 0) {\n continue;\n }\n\n PoolInfo storage pool = poolInfo[pid];\n\n updatePool(pid);\n uint256 oldFactor = user.factor;\n (uint256 accJoePerShare, uint256 accJoePerFactorPerShare) = (\n pool.accJoePerShare,\n pool.accJoePerFactorPerShare\n );\n uint256 pending = amount\n .mul(accJoePerShare)\n .add(oldFactor.mul(accJoePerFactorPerShare))\n .div(_ACC_TOKEN_PRECISION)\n .sub(user.rewardDebt);\n\n // Increase claimableJoe\n claimableJoe[pid][_user] = claimableJoe[pid][_user].add(pending);\n\n // Update users veJoeBalance\n uint256 newFactor = _getUserFactor(amount, _newVeJoeBalance);\n user.factor = newFactor;\n pool.totalFactor = pool.totalFactor.add(newFactor).sub(oldFactor);\n\n user.rewardDebt = amount.mul(accJoePerShare).add(newFactor.mul(accJoePerFactorPerShare)).div(\n _ACC_TOKEN_PRECISION\n );\n\n // Update the pool total veJoe\n }\n }\n\n /// @notice Withdraw without caring about rewards (EMERGENCY ONLY)\n /// @param _pid The index of the pool. See `poolInfo`\n function emergencyWithdraw(uint256 _pid) external nonReentrant {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_msgSender()];\n\n pool.totalFactor = pool.totalFactor.sub(user.factor);\n pool.totalLpSupply = pool.totalLpSupply.sub(user.amount);\n uint256 amount = user.amount;\n user.amount = 0;\n user.rewardDebt = 0;\n user.factor = 0;\n\n IRewarder _rewarder = pool.rewarder;\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(_msgSender(), 0);\n }\n\n // Note: transfer can fail or succeed if `amount` is zero\n pool.lpToken.safeTransfer(_msgSender(), amount);\n emit EmergencyWithdraw(_msgSender(), _pid, amount);\n }\n\n /// @notice Calculates and returns the `amount` of JOE per second\n /// @return amount The amount of JOE emitted per second\n function joePerSec() public view returns (uint256 amount) {\n uint256 total = 1000;\n uint256 lpPercent = total.sub(MASTER_CHEF_V2.devPercent()).sub(MASTER_CHEF_V2.treasuryPercent()).sub(\n MASTER_CHEF_V2.investorPercent()\n );\n uint256 lpShare = MASTER_CHEF_V2.joePerSec().mul(lpPercent).div(total);\n amount = lpShare.mul(MASTER_CHEF_V2.poolInfo(MASTER_PID).allocPoint).div(MASTER_CHEF_V2.totalAllocPoint());\n }\n\n /// @notice View function to see pending JOE on frontend\n /// @param _pid The index of the pool. See `poolInfo`\n /// @param _user Address of user\n /// @return pendingJoe JOE reward for a given user.\n /// @return bonusTokenAddress The address of the bonus reward.\n /// @return bonusTokenSymbol The symbol of the bonus token.\n /// @return pendingBonusToken The amount of bonus rewards pending.\n function pendingTokens(uint256 _pid, address _user)\n external\n view\n returns (\n uint256 pendingJoe,\n address bonusTokenAddress,\n string memory bonusTokenSymbol,\n uint256 pendingBonusToken\n )\n {\n PoolInfo memory pool = poolInfo[_pid];\n UserInfo memory user = userInfo[_pid][_user];\n uint256 accJoePerShare = pool.accJoePerShare;\n uint256 accJoePerFactorPerShare = pool.accJoePerFactorPerShare;\n\n if (block.timestamp > pool.lastRewardTimestamp && pool.totalLpSupply != 0 && pool.allocPoint != 0) {\n uint256 secondsElapsed = block.timestamp - pool.lastRewardTimestamp;\n uint256 joeReward = secondsElapsed.mul(joePerSec()).mul(pool.allocPoint).div(totalAllocPoint);\n accJoePerShare = accJoePerShare.add(\n joeReward.mul(ACC_TOKEN_PRECISION).mul(10_000 - pool.veJoeShareBp).div(pool.totalLpSupply.mul(10_000))\n );\n if (pool.veJoeShareBp != 0 && pool.totalFactor != 0) {\n accJoePerFactorPerShare = accJoePerFactorPerShare.add(\n joeReward.mul(ACC_TOKEN_PRECISION).mul(pool.veJoeShareBp).div(pool.totalFactor.mul(10_000))\n );\n }\n }\n\n pendingJoe = (user.amount.mul(accJoePerShare))\n .add(user.factor.mul(accJoePerFactorPerShare))\n .div(ACC_TOKEN_PRECISION)\n .add(claimableJoe[_pid][_user])\n .sub(user.rewardDebt);\n\n // If it's a double reward farm, we return info about the bonus token\n if (address(pool.rewarder) != address(0)) {\n bonusTokenAddress = address(pool.rewarder.rewardToken());\n bonusTokenSymbol = IERC20(bonusTokenAddress).safeSymbol();\n pendingBonusToken = pool.rewarder.pendingTokens(_user);\n }\n }\n\n /// @notice Returns the number of BMCJ pools.\n /// @return pools The amount of pools in this farm\n function poolLength() external view returns (uint256 pools) {\n pools = poolInfo.length;\n }\n\n /// @notice Update reward variables for all pools. Be careful of gas spending!\n function massUpdatePools() public {\n uint256 len = poolInfo.length;\n for (uint256 i = 0; i < len; ++i) {\n updatePool(i);\n }\n }\n\n /// @notice Update reward variables of the given pool\n /// @param _pid The index of the pool. See `poolInfo`\n function updatePool(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n uint256 lastRewardTimestamp = pool.lastRewardTimestamp;\n if (block.timestamp > lastRewardTimestamp) {\n uint256 lpSupply = pool.totalLpSupply;\n uint256 allocPoint = pool.allocPoint;\n // gas opt and prevent div by 0\n if (lpSupply != 0 && allocPoint != 0) {\n uint256 secondsElapsed = block.timestamp - lastRewardTimestamp;\n uint256 veJoeShareBp = pool.veJoeShareBp;\n uint256 totalFactor = pool.totalFactor;\n\n uint256 joeReward = secondsElapsed.mul(joePerSec()).mul(allocPoint).div(totalAllocPoint);\n pool.accJoePerShare = pool.accJoePerShare.add(\n joeReward.mul(ACC_TOKEN_PRECISION).mul(10_000 - veJoeShareBp).div(lpSupply.mul(10_000))\n );\n // If veJoeShareBp is 0, then we don't need to update it\n if (veJoeShareBp != 0 && totalFactor != 0) {\n pool.accJoePerFactorPerShare = pool.accJoePerFactorPerShare.add(\n joeReward.mul(ACC_TOKEN_PRECISION).mul(veJoeShareBp).div(totalFactor.mul(10_000))\n );\n }\n }\n pool.lastRewardTimestamp = uint64(block.timestamp);\n emit UpdatePool(\n _pid,\n pool.lastRewardTimestamp,\n lpSupply,\n pool.accJoePerShare,\n pool.accJoePerFactorPerShare\n );\n }\n }\n\n /// @notice Harvests JOE from `MASTER_CHEF_V2` MCJV2 and pool `MASTER_PID` to this BMCJ contract\n function harvestFromMasterChef() public {\n MASTER_CHEF_V2.deposit(MASTER_PID, 0);\n }\n\n /// @notice Return an user's factor\n /// @param amount The user's amount of liquidity\n /// @param veJoeBalance The user's veJoe balance\n /// @return uint256 The user's factor\n function _getUserFactor(uint256 amount, uint256 veJoeBalance) private pure returns (uint256) {\n return Math.sqrt(amount * veJoeBalance);\n }\n\n /// @notice Updates user and pool infos\n /// @param _user The user that needs to be updated\n /// @param _pool The pool that needs to be updated\n /// @param _amount The amount that was deposited or withdrawn\n /// @param _isDeposit If the action of the user is a deposit\n function _updateUserAndPool(\n UserInfo storage _user,\n PoolInfo storage _pool,\n uint256 _amount,\n bool _isDeposit\n ) private {\n uint256 oldAmount = _user.amount;\n uint256 newAmount = _isDeposit ? oldAmount.add(_amount) : oldAmount.sub(_amount);\n\n if (_amount != 0) {\n _user.amount = newAmount;\n _pool.totalLpSupply = _isDeposit ? _pool.totalLpSupply.add(_amount) : _pool.totalLpSupply.sub(_amount);\n }\n\n uint256 oldFactor = _user.factor;\n uint256 newFactor = _getUserFactor(newAmount, VEJOE.balanceOf(_msgSender()));\n\n if (oldFactor != newFactor) {\n _user.factor = newFactor;\n _pool.totalFactor = _pool.totalFactor.add(newFactor).sub(oldFactor);\n }\n\n _user.rewardDebt = newAmount.mul(_pool.accJoePerShare).add(newFactor.mul(_pool.accJoePerFactorPerShare)).div(\n ACC_TOKEN_PRECISION\n );\n }\n\n /// @notice Harvests user's pending JOE\n /// @dev WARNING this function doesn't update user's rewardDebt,\n /// it still needs to be updated in order for this contract to work properlly\n /// @param _user The user that will harvest its rewards\n /// @param _pool The pool where the user staked and want to harvest its JOE\n /// @param _pid The pid of that pool\n function _harvestJoe(\n UserInfo storage _user,\n PoolInfo storage _pool,\n uint256 _pid\n ) private {\n uint256 pending = (_user.amount.mul(_pool.accJoePerShare))\n .add(_user.factor.mul(_pool.accJoePerFactorPerShare))\n .div(ACC_TOKEN_PRECISION)\n .add(claimableJoe[_pid][_msgSender()])\n .sub(_user.rewardDebt);\n claimableJoe[_pid][_msgSender()] = 0;\n if (pending != 0) {\n JOE.safeTransfer(_msgSender(), pending);\n emit Harvest(_msgSender(), _pid, pending);\n }\n }\n}\n" + }, + "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../GSN/ContextUpgradeable.sol\";\nimport \"../proxy/Initializable.sol\";\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __Ownable_init() internal initializer {\n __Context_init_unchained();\n __Ownable_init_unchained();\n }\n\n function __Ownable_init_unchained() internal initializer {\n address msgSender = _msgSender();\n _owner = msgSender;\n emit OwnershipTransferred(address(0), msgSender);\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(_owner == _msgSender(), \"Ownable: caller is not the owner\");\n _;\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n emit OwnershipTransferred(_owner, address(0));\n _owner = address(0);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n emit OwnershipTransferred(_owner, newOwner);\n _owner = newOwner;\n }\n uint256[49] private __gap;\n}\n" + }, + "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMathUpgradeable {\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n *\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n return sub(a, b, \"SafeMath: subtraction overflow\");\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b <= a, errorMessage);\n uint256 c = a - b;\n\n return c;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n *\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n return div(a, b, \"SafeMath: division by zero\");\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b > 0, errorMessage);\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n return c;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n return mod(a, b, \"SafeMath: modulo by zero\");\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts with custom message when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b != 0, errorMessage);\n return a % b;\n }\n}\n" + }, + "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// solhint-disable-next-line compiler-version\npragma solidity >=0.4.24 <0.8.0;\n\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n * \n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}.\n * \n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n */\nabstract contract Initializable {\n\n /**\n * @dev Indicates that the contract has been initialized.\n */\n bool private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Modifier to protect an initializer function from being invoked twice.\n */\n modifier initializer() {\n require(_initializing || _isConstructor() || !_initialized, \"Initializable: contract is already initialized\");\n\n bool isTopLevelCall = !_initializing;\n if (isTopLevelCall) {\n _initializing = true;\n _initialized = true;\n }\n\n _;\n\n if (isTopLevelCall) {\n _initializing = false;\n }\n }\n\n /// @dev Returns true if and only if the function is running in the constructor\n function _isConstructor() private view returns (bool) {\n // extcodesize checks the size of the code stored in an address, and\n // address returns the current address. Since the code is still not\n // deployed when running a constructor, any checks on its code size will\n // yield zero, making it an effective way to detect if a contract is\n // under construction or not.\n address self = address(this);\n uint256 cs;\n // solhint-disable-next-line no-inline-assembly\n assembly { cs := extcodesize(self) }\n return cs == 0;\n }\n}\n" + }, + "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\nimport \"../proxy/Initializable.sol\";\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuardUpgradeable is Initializable {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n function __ReentrancyGuard_init() internal initializer {\n __ReentrancyGuard_init_unchained();\n }\n\n function __ReentrancyGuard_init_unchained() internal initializer {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and make it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n uint256[49] private __gap;\n}\n" + }, + "contracts/interfaces/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\ninterface IERC20 {\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 amount) external returns (bool);\n\n event Transfer(address indexed from, address indexed to, uint256 value);\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n // EIP 2612\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n}\n" + }, + "contracts/interfaces/IMasterChefJoe.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\nimport \"../libraries/BoringJoeERC20.sol\";\n\ninterface IMasterChefJoe {\n using BoringJoeERC20 for IERC20;\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\n }\n\n function userInfo(uint256 _pid, address _user) external view returns (IMasterChefJoe.UserInfo memory);\n\n function poolInfo(uint256 pid) external view returns (IMasterChefJoe.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function joePerSec() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n\n function devPercent() external view returns (uint256);\n\n function treasuryPercent() external view returns (uint256);\n\n function investorPercent() external view returns (uint256);\n}\n" + }, + "contracts/interfaces/IRewarder.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\nimport \"./IERC20.sol\";\n\ninterface IRewarder {\n function onJoeReward(address user, uint256 newLpAmount) external;\n\n function pendingTokens(address user) external view returns (uint256 pending);\n\n function rewardToken() external view returns (IERC20);\n}\n" + }, + "contracts/libraries/BoringJoeERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\nimport \"../interfaces/IERC20.sol\";\n\n// solhint-disable avoid-low-level-calls\n\nlibrary BoringJoeERC20 {\n bytes4 private constant SIG_SYMBOL = 0x95d89b41; // symbol()\n bytes4 private constant SIG_NAME = 0x06fdde03; // name()\n bytes4 private constant SIG_DECIMALS = 0x313ce567; // decimals()\n bytes4 private constant SIG_TRANSFER = 0xa9059cbb; // transfer(address,uint256)\n bytes4 private constant SIG_TRANSFER_FROM = 0x23b872dd; // transferFrom(address,address,uint256)\n\n function returnDataToString(bytes memory data) internal pure returns (string memory) {\n if (data.length >= 64) {\n return abi.decode(data, (string));\n } else if (data.length == 32) {\n uint8 i = 0;\n while (i < 32 && data[i] != 0) {\n i++;\n }\n bytes memory bytesArray = new bytes(i);\n for (i = 0; i < 32 && data[i] != 0; i++) {\n bytesArray[i] = data[i];\n }\n return string(bytesArray);\n } else {\n return \"???\";\n }\n }\n\n /// @notice Provides a safe ERC20.symbol version which returns '???' as fallback string.\n /// @param token The address of the ERC-20 token contract.\n /// @return (string) Token symbol.\n function safeSymbol(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_SYMBOL));\n return success ? returnDataToString(data) : \"???\";\n }\n\n /// @notice Provides a safe ERC20.name version which returns '???' as fallback string.\n /// @param token The address of the ERC-20 token contract.\n /// @return (string) Token name.\n function safeName(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_NAME));\n return success ? returnDataToString(data) : \"???\";\n }\n\n /// @notice Provides a safe ERC20.decimals version which returns '18' as fallback value.\n /// @param token The address of the ERC-20 token contract.\n /// @return (uint8) Token decimals.\n function safeDecimals(IERC20 token) internal view returns (uint8) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_DECIMALS));\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\n }\n\n /// @notice Provides a safe ERC20.transfer version for different ERC-20 implementations.\n /// Reverts on a failed transfer.\n /// @param token The address of the ERC-20 token.\n /// @param to Transfer tokens to.\n /// @param amount The token amount.\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(SIG_TRANSFER, to, amount));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"BoringERC20: Transfer failed\");\n }\n\n /// @notice Provides a safe ERC20.transferFrom version for different ERC-20 implementations.\n /// Reverts on a failed transfer.\n /// @param token The address of the ERC-20 token.\n /// @param from Transfer tokens from.\n /// @param to Transfer tokens to.\n /// @param amount The token amount.\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(\n abi.encodeWithSelector(SIG_TRANSFER_FROM, from, to, amount)\n );\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"BoringERC20: TransferFrom failed\");\n }\n}\n" + }, + "contracts/traderjoe/libraries/Math.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\n// a library for performing various math operations\n\nlibrary Math {\n function min(uint256 x, uint256 y) internal pure returns (uint256 z) {\n z = x < y ? x : y;\n }\n\n // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)\n function sqrt(uint256 y) internal pure returns (uint256 z) {\n if (y > 3) {\n z = y;\n uint256 x = y / 2 + 1;\n while (x < z) {\n z = x;\n x = (y / x + x) / 2;\n }\n } else if (y != 0) {\n z = 1;\n }\n }\n}\n" + }, + "@openzeppelin/contracts-upgradeable/GSN/ContextUpgradeable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\nimport \"../proxy/Initializable.sol\";\n\n/*\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with GSN meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n function __Context_init() internal initializer {\n __Context_init_unchained();\n }\n\n function __Context_init_unchained() internal initializer {\n }\n function _msgSender() internal view virtual returns (address payable) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes memory) {\n this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n return msg.data;\n }\n uint256[50] private __gap;\n}\n" + }, + "contracts/traderjoe/JoePair.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\nimport \"./JoeERC20.sol\";\nimport \"./libraries/Math.sol\";\nimport \"./libraries/UQ112x112.sol\";\nimport \"./interfaces/IERC20.sol\";\nimport \"./interfaces/IJoeFactory.sol\";\nimport \"./interfaces/IJoeCallee.sol\";\n\ninterface IMigrator {\n // Return the desired amount of liquidity token that the migrator wants.\n function desiredLiquidity() external view returns (uint256);\n}\n\ncontract JoePair is JoeERC20 {\n using SafeMathJoe for uint256;\n using UQ112x112 for uint224;\n\n uint256 public constant MINIMUM_LIQUIDITY = 10**3;\n bytes4 private constant SELECTOR = bytes4(keccak256(bytes(\"transfer(address,uint256)\")));\n\n address public factory;\n address public token0;\n address public token1;\n\n uint112 private reserve0; // uses single storage slot, accessible via getReserves\n uint112 private reserve1; // uses single storage slot, accessible via getReserves\n uint32 private blockTimestampLast; // uses single storage slot, accessible via getReserves\n\n uint256 public price0CumulativeLast;\n uint256 public price1CumulativeLast;\n uint256 public kLast; // reserve0 * reserve1, as of immediately after the most recent liquidity event\n\n uint256 private unlocked = 1;\n modifier lock() {\n require(unlocked == 1, \"Joe: LOCKED\");\n unlocked = 0;\n _;\n unlocked = 1;\n }\n\n function getReserves()\n public\n view\n returns (\n uint112 _reserve0,\n uint112 _reserve1,\n uint32 _blockTimestampLast\n )\n {\n _reserve0 = reserve0;\n _reserve1 = reserve1;\n _blockTimestampLast = blockTimestampLast;\n }\n\n function _safeTransfer(\n address token,\n address to,\n uint256 value\n ) private {\n (bool success, bytes memory data) = token.call(abi.encodeWithSelector(SELECTOR, to, value));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"Joe: TRANSFER_FAILED\");\n }\n\n event Mint(address indexed sender, uint256 amount0, uint256 amount1);\n event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);\n event Swap(\n address indexed sender,\n uint256 amount0In,\n uint256 amount1In,\n uint256 amount0Out,\n uint256 amount1Out,\n address indexed to\n );\n event Sync(uint112 reserve0, uint112 reserve1);\n\n constructor() public {\n factory = msg.sender;\n }\n\n // called once by the factory at time of deployment\n function initialize(address _token0, address _token1) external {\n require(msg.sender == factory, \"Joe: FORBIDDEN\"); // sufficient check\n token0 = _token0;\n token1 = _token1;\n }\n\n // update reserves and, on the first call per block, price accumulators\n function _update(\n uint256 balance0,\n uint256 balance1,\n uint112 _reserve0,\n uint112 _reserve1\n ) private {\n require(balance0 <= uint112(-1) && balance1 <= uint112(-1), \"Joe: OVERFLOW\");\n uint32 blockTimestamp = uint32(block.timestamp % 2**32);\n uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired\n if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) {\n // * never overflows, and + overflow is desired\n price0CumulativeLast += uint256(UQ112x112.encode(_reserve1).uqdiv(_reserve0)) * timeElapsed;\n price1CumulativeLast += uint256(UQ112x112.encode(_reserve0).uqdiv(_reserve1)) * timeElapsed;\n }\n reserve0 = uint112(balance0);\n reserve1 = uint112(balance1);\n blockTimestampLast = blockTimestamp;\n emit Sync(reserve0, reserve1);\n }\n\n // if fee is on, mint liquidity equivalent to 1/6th of the growth in sqrt(k)\n function _mintFee(uint112 _reserve0, uint112 _reserve1) private returns (bool feeOn) {\n address feeTo = IJoeFactory(factory).feeTo();\n feeOn = feeTo != address(0);\n uint256 _kLast = kLast; // gas savings\n if (feeOn) {\n if (_kLast != 0) {\n uint256 rootK = Math.sqrt(uint256(_reserve0).mul(_reserve1));\n uint256 rootKLast = Math.sqrt(_kLast);\n if (rootK > rootKLast) {\n uint256 numerator = totalSupply.mul(rootK.sub(rootKLast));\n uint256 denominator = rootK.mul(5).add(rootKLast);\n uint256 liquidity = numerator / denominator;\n if (liquidity > 0) _mint(feeTo, liquidity);\n }\n }\n } else if (_kLast != 0) {\n kLast = 0;\n }\n }\n\n // this low-level function should be called from a contract which performs important safety checks\n function mint(address to) external lock returns (uint256 liquidity) {\n (uint112 _reserve0, uint112 _reserve1, ) = getReserves(); // gas savings\n uint256 balance0 = IERC20Joe(token0).balanceOf(address(this));\n uint256 balance1 = IERC20Joe(token1).balanceOf(address(this));\n uint256 amount0 = balance0.sub(_reserve0);\n uint256 amount1 = balance1.sub(_reserve1);\n\n bool feeOn = _mintFee(_reserve0, _reserve1);\n uint256 _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee\n if (_totalSupply == 0) {\n address migrator = IJoeFactory(factory).migrator();\n if (msg.sender == migrator) {\n liquidity = IMigrator(migrator).desiredLiquidity();\n require(liquidity > 0 && liquidity != uint256(-1), \"Bad desired liquidity\");\n } else {\n require(migrator == address(0), \"Must not have migrator\");\n liquidity = Math.sqrt(amount0.mul(amount1)).sub(MINIMUM_LIQUIDITY);\n _mint(address(0), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens\n }\n } else {\n liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1);\n }\n require(liquidity > 0, \"Joe: INSUFFICIENT_LIQUIDITY_MINTED\");\n _mint(to, liquidity);\n\n _update(balance0, balance1, _reserve0, _reserve1);\n if (feeOn) kLast = uint256(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date\n emit Mint(msg.sender, amount0, amount1);\n }\n\n // this low-level function should be called from a contract which performs important safety checks\n function burn(address to) external lock returns (uint256 amount0, uint256 amount1) {\n (uint112 _reserve0, uint112 _reserve1, ) = getReserves(); // gas savings\n address _token0 = token0; // gas savings\n address _token1 = token1; // gas savings\n uint256 balance0 = IERC20Joe(_token0).balanceOf(address(this));\n uint256 balance1 = IERC20Joe(_token1).balanceOf(address(this));\n uint256 liquidity = balanceOf[address(this)];\n\n bool feeOn = _mintFee(_reserve0, _reserve1);\n uint256 _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee\n amount0 = liquidity.mul(balance0) / _totalSupply; // using balances ensures pro-rata distribution\n amount1 = liquidity.mul(balance1) / _totalSupply; // using balances ensures pro-rata distribution\n require(amount0 > 0 && amount1 > 0, \"Joe: INSUFFICIENT_LIQUIDITY_BURNED\");\n _burn(address(this), liquidity);\n _safeTransfer(_token0, to, amount0);\n _safeTransfer(_token1, to, amount1);\n balance0 = IERC20Joe(_token0).balanceOf(address(this));\n balance1 = IERC20Joe(_token1).balanceOf(address(this));\n\n _update(balance0, balance1, _reserve0, _reserve1);\n if (feeOn) kLast = uint256(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date\n emit Burn(msg.sender, amount0, amount1, to);\n }\n\n // this low-level function should be called from a contract which performs important safety checks\n function swap(\n uint256 amount0Out,\n uint256 amount1Out,\n address to,\n bytes calldata data\n ) external lock {\n require(amount0Out > 0 || amount1Out > 0, \"Joe: INSUFFICIENT_OUTPUT_AMOUNT\");\n (uint112 _reserve0, uint112 _reserve1, ) = getReserves(); // gas savings\n require(amount0Out < _reserve0 && amount1Out < _reserve1, \"Joe: INSUFFICIENT_LIQUIDITY\");\n\n uint256 balance0;\n uint256 balance1;\n {\n // scope for _token{0,1}, avoids stack too deep errors\n address _token0 = token0;\n address _token1 = token1;\n require(to != _token0 && to != _token1, \"Joe: INVALID_TO\");\n if (amount0Out > 0) _safeTransfer(_token0, to, amount0Out); // optimistically transfer tokens\n if (amount1Out > 0) _safeTransfer(_token1, to, amount1Out); // optimistically transfer tokens\n if (data.length > 0) IJoeCallee(to).joeCall(msg.sender, amount0Out, amount1Out, data);\n balance0 = IERC20Joe(_token0).balanceOf(address(this));\n balance1 = IERC20Joe(_token1).balanceOf(address(this));\n }\n uint256 amount0In = balance0 > _reserve0 - amount0Out ? balance0 - (_reserve0 - amount0Out) : 0;\n uint256 amount1In = balance1 > _reserve1 - amount1Out ? balance1 - (_reserve1 - amount1Out) : 0;\n require(amount0In > 0 || amount1In > 0, \"Joe: INSUFFICIENT_INPUT_AMOUNT\");\n {\n // scope for reserve{0,1}Adjusted, avoids stack too deep errors\n uint256 balance0Adjusted = balance0.mul(1000).sub(amount0In.mul(3));\n uint256 balance1Adjusted = balance1.mul(1000).sub(amount1In.mul(3));\n require(balance0Adjusted.mul(balance1Adjusted) >= uint256(_reserve0).mul(_reserve1).mul(1000**2), \"Joe: K\");\n }\n\n _update(balance0, balance1, _reserve0, _reserve1);\n emit Swap(msg.sender, amount0In, amount1In, amount0Out, amount1Out, to);\n }\n\n // force balances to match reserves\n function skim(address to) external lock {\n address _token0 = token0; // gas savings\n address _token1 = token1; // gas savings\n _safeTransfer(_token0, to, IERC20Joe(_token0).balanceOf(address(this)).sub(reserve0));\n _safeTransfer(_token1, to, IERC20Joe(_token1).balanceOf(address(this)).sub(reserve1));\n }\n\n // force reserves to match balances\n function sync() external lock {\n _update(\n IERC20Joe(token0).balanceOf(address(this)),\n IERC20Joe(token1).balanceOf(address(this)),\n reserve0,\n reserve1\n );\n }\n}\n" + }, + "contracts/traderjoe/JoeERC20.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\nimport \"./libraries/SafeMath.sol\";\n\ncontract JoeERC20 {\n using SafeMathJoe for uint256;\n\n string public constant name = \"Joe LP Token\";\n string public constant symbol = \"JLP\";\n uint8 public constant decimals = 18;\n uint256 public totalSupply;\n mapping(address => uint256) public balanceOf;\n mapping(address => mapping(address => uint256)) public allowance;\n\n bytes32 public DOMAIN_SEPARATOR;\n // keccak256(\"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)\");\n bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;\n mapping(address => uint256) public nonces;\n\n event Approval(address indexed owner, address indexed spender, uint256 value);\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n constructor() public {\n uint256 chainId;\n assembly {\n chainId := chainid()\n }\n DOMAIN_SEPARATOR = keccak256(\n abi.encode(\n keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\"),\n keccak256(bytes(name)),\n keccak256(bytes(\"1\")),\n chainId,\n address(this)\n )\n );\n }\n\n function _mint(address to, uint256 value) internal {\n totalSupply = totalSupply.add(value);\n balanceOf[to] = balanceOf[to].add(value);\n emit Transfer(address(0), to, value);\n }\n\n function _burn(address from, uint256 value) internal {\n balanceOf[from] = balanceOf[from].sub(value);\n totalSupply = totalSupply.sub(value);\n emit Transfer(from, address(0), value);\n }\n\n function _approve(\n address owner,\n address spender,\n uint256 value\n ) private {\n allowance[owner][spender] = value;\n emit Approval(owner, spender, value);\n }\n\n function _transfer(\n address from,\n address to,\n uint256 value\n ) private {\n balanceOf[from] = balanceOf[from].sub(value);\n balanceOf[to] = balanceOf[to].add(value);\n emit Transfer(from, to, value);\n }\n\n function approve(address spender, uint256 value) external returns (bool) {\n _approve(msg.sender, spender, value);\n return true;\n }\n\n function transfer(address to, uint256 value) external returns (bool) {\n _transfer(msg.sender, to, value);\n return true;\n }\n\n function transferFrom(\n address from,\n address to,\n uint256 value\n ) external returns (bool) {\n if (allowance[from][msg.sender] != uint256(-1)) {\n allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);\n }\n _transfer(from, to, value);\n return true;\n }\n\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external {\n require(deadline >= block.timestamp, \"Joe: EXPIRED\");\n bytes32 digest = keccak256(\n abi.encodePacked(\n \"\\x19\\x01\",\n DOMAIN_SEPARATOR,\n keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))\n )\n );\n address recoveredAddress = ecrecover(digest, v, r, s);\n require(recoveredAddress != address(0) && recoveredAddress == owner, \"Joe: INVALID_SIGNATURE\");\n _approve(owner, spender, value);\n }\n}\n" + }, + "contracts/traderjoe/libraries/UQ112x112.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\n// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))\n\n// range: [0, 2**112 - 1]\n// resolution: 1 / 2**112\n\nlibrary UQ112x112 {\n uint224 constant Q112 = 2**112;\n\n // encode a uint112 as a UQ112x112\n function encode(uint112 y) internal pure returns (uint224 z) {\n z = uint224(y) * Q112; // never overflows\n }\n\n // divide a UQ112x112 by a uint112, returning a UQ112x112\n function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) {\n z = x / uint224(y);\n }\n}\n" + }, + "contracts/traderjoe/interfaces/IERC20.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\ninterface IERC20Joe {\n event Approval(address indexed owner, address indexed spender, uint256 value);\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n function name() external view returns (string memory);\n\n function symbol() external view returns (string memory);\n\n function decimals() external view returns (uint8);\n\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address owner) external view returns (uint256);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 value) external returns (bool);\n\n function transfer(address to, uint256 value) external returns (bool);\n\n function transferFrom(\n address from,\n address to,\n uint256 value\n ) external returns (bool);\n}\n" + }, + "contracts/traderjoe/interfaces/IJoeFactory.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\ninterface IJoeFactory {\n event PairCreated(address indexed token0, address indexed token1, address pair, uint256);\n\n function feeTo() external view returns (address);\n\n function feeToSetter() external view returns (address);\n\n function migrator() external view returns (address);\n\n function getPair(address tokenA, address tokenB) external view returns (address pair);\n\n function allPairs(uint256) external view returns (address pair);\n\n function allPairsLength() external view returns (uint256);\n\n function createPair(address tokenA, address tokenB) external returns (address pair);\n\n function setFeeTo(address) external;\n\n function setFeeToSetter(address) external;\n\n function setMigrator(address) external;\n}\n" + }, + "contracts/traderjoe/interfaces/IJoeCallee.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\ninterface IJoeCallee {\n function joeCall(\n address sender,\n uint256 amount0,\n uint256 amount1,\n bytes calldata data\n ) external;\n}\n" + }, + "contracts/traderjoe/libraries/SafeMath.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\n// a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)\n\nlibrary SafeMathJoe {\n function add(uint256 x, uint256 y) internal pure returns (uint256 z) {\n require((z = x + y) >= x, \"ds-math-add-overflow\");\n }\n\n function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {\n require((z = x - y) <= x, \"ds-math-sub-underflow\");\n }\n\n function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {\n require(y == 0 || (z = x * y) / y == x, \"ds-math-mul-overflow\");\n }\n}\n" + }, + "contracts/traderjoe/JoeRouter02.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\nimport \"./libraries/JoeLibrary.sol\";\nimport \"./libraries/SafeMath.sol\";\nimport \"./libraries/TransferHelper.sol\";\nimport \"./interfaces/IJoeRouter02.sol\";\nimport \"./interfaces/IJoeFactory.sol\";\nimport \"./interfaces/IERC20.sol\";\nimport \"./interfaces/IWAVAX.sol\";\n\ncontract JoeRouter02 is IJoeRouter02 {\n using SafeMathJoe for uint256;\n\n address public immutable override factory;\n address public immutable override WAVAX;\n\n modifier ensure(uint256 deadline) {\n require(deadline >= block.timestamp, \"JoeRouter: EXPIRED\");\n _;\n }\n\n constructor(address _factory, address _WAVAX) public {\n factory = _factory;\n WAVAX = _WAVAX;\n }\n\n receive() external payable {\n assert(msg.sender == WAVAX); // only accept AVAX via fallback from the WAVAX contract\n }\n\n // **** ADD LIQUIDITY ****\n function _addLiquidity(\n address tokenA,\n address tokenB,\n uint256 amountADesired,\n uint256 amountBDesired,\n uint256 amountAMin,\n uint256 amountBMin\n ) internal virtual returns (uint256 amountA, uint256 amountB) {\n // create the pair if it doesn't exist yet\n if (IJoeFactory(factory).getPair(tokenA, tokenB) == address(0)) {\n IJoeFactory(factory).createPair(tokenA, tokenB);\n }\n (uint256 reserveA, uint256 reserveB) = JoeLibrary.getReserves(factory, tokenA, tokenB);\n if (reserveA == 0 && reserveB == 0) {\n (amountA, amountB) = (amountADesired, amountBDesired);\n } else {\n uint256 amountBOptimal = JoeLibrary.quote(amountADesired, reserveA, reserveB);\n if (amountBOptimal <= amountBDesired) {\n require(amountBOptimal >= amountBMin, \"JoeRouter: INSUFFICIENT_B_AMOUNT\");\n (amountA, amountB) = (amountADesired, amountBOptimal);\n } else {\n uint256 amountAOptimal = JoeLibrary.quote(amountBDesired, reserveB, reserveA);\n assert(amountAOptimal <= amountADesired);\n require(amountAOptimal >= amountAMin, \"JoeRouter: INSUFFICIENT_A_AMOUNT\");\n (amountA, amountB) = (amountAOptimal, amountBDesired);\n }\n }\n }\n\n function addLiquidity(\n address tokenA,\n address tokenB,\n uint256 amountADesired,\n uint256 amountBDesired,\n uint256 amountAMin,\n uint256 amountBMin,\n address to,\n uint256 deadline\n )\n external\n virtual\n override\n ensure(deadline)\n returns (\n uint256 amountA,\n uint256 amountB,\n uint256 liquidity\n )\n {\n (amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin);\n address pair = JoeLibrary.pairFor(factory, tokenA, tokenB);\n TransferHelper.safeTransferFrom(tokenA, msg.sender, pair, amountA);\n TransferHelper.safeTransferFrom(tokenB, msg.sender, pair, amountB);\n liquidity = IJoePair(pair).mint(to);\n }\n\n function addLiquidityAVAX(\n address token,\n uint256 amountTokenDesired,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline\n )\n external\n payable\n virtual\n override\n ensure(deadline)\n returns (\n uint256 amountToken,\n uint256 amountAVAX,\n uint256 liquidity\n )\n {\n (amountToken, amountAVAX) = _addLiquidity(\n token,\n WAVAX,\n amountTokenDesired,\n msg.value,\n amountTokenMin,\n amountAVAXMin\n );\n address pair = JoeLibrary.pairFor(factory, token, WAVAX);\n TransferHelper.safeTransferFrom(token, msg.sender, pair, amountToken);\n IWAVAX(WAVAX).deposit{value: amountAVAX}();\n assert(IWAVAX(WAVAX).transfer(pair, amountAVAX));\n liquidity = IJoePair(pair).mint(to);\n // refund dust eth, if any\n if (msg.value > amountAVAX) TransferHelper.safeTransferAVAX(msg.sender, msg.value - amountAVAX);\n }\n\n // **** REMOVE LIQUIDITY ****\n function removeLiquidity(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n address to,\n uint256 deadline\n ) public virtual override ensure(deadline) returns (uint256 amountA, uint256 amountB) {\n address pair = JoeLibrary.pairFor(factory, tokenA, tokenB);\n IJoePair(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair\n (uint256 amount0, uint256 amount1) = IJoePair(pair).burn(to);\n (address token0, ) = JoeLibrary.sortTokens(tokenA, tokenB);\n (amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0);\n require(amountA >= amountAMin, \"JoeRouter: INSUFFICIENT_A_AMOUNT\");\n require(amountB >= amountBMin, \"JoeRouter: INSUFFICIENT_B_AMOUNT\");\n }\n\n function removeLiquidityAVAX(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline\n ) public virtual override ensure(deadline) returns (uint256 amountToken, uint256 amountAVAX) {\n (amountToken, amountAVAX) = removeLiquidity(\n token,\n WAVAX,\n liquidity,\n amountTokenMin,\n amountAVAXMin,\n address(this),\n deadline\n );\n TransferHelper.safeTransfer(token, to, amountToken);\n IWAVAX(WAVAX).withdraw(amountAVAX);\n TransferHelper.safeTransferAVAX(to, amountAVAX);\n }\n\n function removeLiquidityWithPermit(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n address to,\n uint256 deadline,\n bool approveMax,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external virtual override returns (uint256 amountA, uint256 amountB) {\n address pair = JoeLibrary.pairFor(factory, tokenA, tokenB);\n uint256 value = approveMax ? uint256(-1) : liquidity;\n IJoePair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);\n (amountA, amountB) = removeLiquidity(tokenA, tokenB, liquidity, amountAMin, amountBMin, to, deadline);\n }\n\n function removeLiquidityAVAXWithPermit(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline,\n bool approveMax,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external virtual override returns (uint256 amountToken, uint256 amountAVAX) {\n address pair = JoeLibrary.pairFor(factory, token, WAVAX);\n uint256 value = approveMax ? uint256(-1) : liquidity;\n IJoePair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);\n (amountToken, amountAVAX) = removeLiquidityAVAX(token, liquidity, amountTokenMin, amountAVAXMin, to, deadline);\n }\n\n // **** REMOVE LIQUIDITY (supporting fee-on-transfer tokens) ****\n function removeLiquidityAVAXSupportingFeeOnTransferTokens(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline\n ) public virtual override ensure(deadline) returns (uint256 amountAVAX) {\n (, amountAVAX) = removeLiquidity(\n token,\n WAVAX,\n liquidity,\n amountTokenMin,\n amountAVAXMin,\n address(this),\n deadline\n );\n TransferHelper.safeTransfer(token, to, IERC20Joe(token).balanceOf(address(this)));\n IWAVAX(WAVAX).withdraw(amountAVAX);\n TransferHelper.safeTransferAVAX(to, amountAVAX);\n }\n\n function removeLiquidityAVAXWithPermitSupportingFeeOnTransferTokens(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline,\n bool approveMax,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external virtual override returns (uint256 amountAVAX) {\n address pair = JoeLibrary.pairFor(factory, token, WAVAX);\n uint256 value = approveMax ? uint256(-1) : liquidity;\n IJoePair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);\n amountAVAX = removeLiquidityAVAXSupportingFeeOnTransferTokens(\n token,\n liquidity,\n amountTokenMin,\n amountAVAXMin,\n to,\n deadline\n );\n }\n\n // **** SWAP ****\n // requires the initial amount to have already been sent to the first pair\n function _swap(\n uint256[] memory amounts,\n address[] memory path,\n address _to\n ) internal virtual {\n for (uint256 i; i < path.length - 1; i++) {\n (address input, address output) = (path[i], path[i + 1]);\n (address token0, ) = JoeLibrary.sortTokens(input, output);\n uint256 amountOut = amounts[i + 1];\n (uint256 amount0Out, uint256 amount1Out) = input == token0\n ? (uint256(0), amountOut)\n : (amountOut, uint256(0));\n address to = i < path.length - 2 ? JoeLibrary.pairFor(factory, output, path[i + 2]) : _to;\n IJoePair(JoeLibrary.pairFor(factory, input, output)).swap(amount0Out, amount1Out, to, new bytes(0));\n }\n }\n\n function swapExactTokensForTokens(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external virtual override ensure(deadline) returns (uint256[] memory amounts) {\n amounts = JoeLibrary.getAmountsOut(factory, amountIn, path);\n require(amounts[amounts.length - 1] >= amountOutMin, \"JoeRouter: INSUFFICIENT_OUTPUT_AMOUNT\");\n TransferHelper.safeTransferFrom(path[0], msg.sender, JoeLibrary.pairFor(factory, path[0], path[1]), amounts[0]);\n _swap(amounts, path, to);\n }\n\n function swapTokensForExactTokens(\n uint256 amountOut,\n uint256 amountInMax,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external virtual override ensure(deadline) returns (uint256[] memory amounts) {\n amounts = JoeLibrary.getAmountsIn(factory, amountOut, path);\n require(amounts[0] <= amountInMax, \"JoeRouter: EXCESSIVE_INPUT_AMOUNT\");\n TransferHelper.safeTransferFrom(path[0], msg.sender, JoeLibrary.pairFor(factory, path[0], path[1]), amounts[0]);\n _swap(amounts, path, to);\n }\n\n function swapExactAVAXForTokens(\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external payable virtual override ensure(deadline) returns (uint256[] memory amounts) {\n require(path[0] == WAVAX, \"JoeRouter: INVALID_PATH\");\n amounts = JoeLibrary.getAmountsOut(factory, msg.value, path);\n require(amounts[amounts.length - 1] >= amountOutMin, \"JoeRouter: INSUFFICIENT_OUTPUT_AMOUNT\");\n IWAVAX(WAVAX).deposit{value: amounts[0]}();\n assert(IWAVAX(WAVAX).transfer(JoeLibrary.pairFor(factory, path[0], path[1]), amounts[0]));\n _swap(amounts, path, to);\n }\n\n function swapTokensForExactAVAX(\n uint256 amountOut,\n uint256 amountInMax,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external virtual override ensure(deadline) returns (uint256[] memory amounts) {\n require(path[path.length - 1] == WAVAX, \"JoeRouter: INVALID_PATH\");\n amounts = JoeLibrary.getAmountsIn(factory, amountOut, path);\n require(amounts[0] <= amountInMax, \"JoeRouter: EXCESSIVE_INPUT_AMOUNT\");\n TransferHelper.safeTransferFrom(path[0], msg.sender, JoeLibrary.pairFor(factory, path[0], path[1]), amounts[0]);\n _swap(amounts, path, address(this));\n IWAVAX(WAVAX).withdraw(amounts[amounts.length - 1]);\n TransferHelper.safeTransferAVAX(to, amounts[amounts.length - 1]);\n }\n\n function swapExactTokensForAVAX(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external virtual override ensure(deadline) returns (uint256[] memory amounts) {\n require(path[path.length - 1] == WAVAX, \"JoeRouter: INVALID_PATH\");\n amounts = JoeLibrary.getAmountsOut(factory, amountIn, path);\n require(amounts[amounts.length - 1] >= amountOutMin, \"JoeRouter: INSUFFICIENT_OUTPUT_AMOUNT\");\n TransferHelper.safeTransferFrom(path[0], msg.sender, JoeLibrary.pairFor(factory, path[0], path[1]), amounts[0]);\n _swap(amounts, path, address(this));\n IWAVAX(WAVAX).withdraw(amounts[amounts.length - 1]);\n TransferHelper.safeTransferAVAX(to, amounts[amounts.length - 1]);\n }\n\n function swapAVAXForExactTokens(\n uint256 amountOut,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external payable virtual override ensure(deadline) returns (uint256[] memory amounts) {\n require(path[0] == WAVAX, \"JoeRouter: INVALID_PATH\");\n amounts = JoeLibrary.getAmountsIn(factory, amountOut, path);\n require(amounts[0] <= msg.value, \"JoeRouter: EXCESSIVE_INPUT_AMOUNT\");\n IWAVAX(WAVAX).deposit{value: amounts[0]}();\n assert(IWAVAX(WAVAX).transfer(JoeLibrary.pairFor(factory, path[0], path[1]), amounts[0]));\n _swap(amounts, path, to);\n // refund dust eth, if any\n if (msg.value > amounts[0]) TransferHelper.safeTransferAVAX(msg.sender, msg.value - amounts[0]);\n }\n\n // **** SWAP (supporting fee-on-transfer tokens) ****\n // requires the initial amount to have already been sent to the first pair\n function _swapSupportingFeeOnTransferTokens(address[] memory path, address _to) internal virtual {\n for (uint256 i; i < path.length - 1; i++) {\n (address input, address output) = (path[i], path[i + 1]);\n (address token0, ) = JoeLibrary.sortTokens(input, output);\n IJoePair pair = IJoePair(JoeLibrary.pairFor(factory, input, output));\n uint256 amountInput;\n uint256 amountOutput;\n {\n // scope to avoid stack too deep errors\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n (uint256 reserveInput, uint256 reserveOutput) = input == token0\n ? (reserve0, reserve1)\n : (reserve1, reserve0);\n amountInput = IERC20Joe(input).balanceOf(address(pair)).sub(reserveInput);\n amountOutput = JoeLibrary.getAmountOut(amountInput, reserveInput, reserveOutput);\n }\n (uint256 amount0Out, uint256 amount1Out) = input == token0\n ? (uint256(0), amountOutput)\n : (amountOutput, uint256(0));\n address to = i < path.length - 2 ? JoeLibrary.pairFor(factory, output, path[i + 2]) : _to;\n pair.swap(amount0Out, amount1Out, to, new bytes(0));\n }\n }\n\n function swapExactTokensForTokensSupportingFeeOnTransferTokens(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external virtual override ensure(deadline) {\n TransferHelper.safeTransferFrom(path[0], msg.sender, JoeLibrary.pairFor(factory, path[0], path[1]), amountIn);\n uint256 balanceBefore = IERC20Joe(path[path.length - 1]).balanceOf(to);\n _swapSupportingFeeOnTransferTokens(path, to);\n require(\n IERC20Joe(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin,\n \"JoeRouter: INSUFFICIENT_OUTPUT_AMOUNT\"\n );\n }\n\n function swapExactAVAXForTokensSupportingFeeOnTransferTokens(\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external payable virtual override ensure(deadline) {\n require(path[0] == WAVAX, \"JoeRouter: INVALID_PATH\");\n uint256 amountIn = msg.value;\n IWAVAX(WAVAX).deposit{value: amountIn}();\n assert(IWAVAX(WAVAX).transfer(JoeLibrary.pairFor(factory, path[0], path[1]), amountIn));\n uint256 balanceBefore = IERC20Joe(path[path.length - 1]).balanceOf(to);\n _swapSupportingFeeOnTransferTokens(path, to);\n require(\n IERC20Joe(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin,\n \"JoeRouter: INSUFFICIENT_OUTPUT_AMOUNT\"\n );\n }\n\n function swapExactTokensForAVAXSupportingFeeOnTransferTokens(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external virtual override ensure(deadline) {\n require(path[path.length - 1] == WAVAX, \"JoeRouter: INVALID_PATH\");\n TransferHelper.safeTransferFrom(path[0], msg.sender, JoeLibrary.pairFor(factory, path[0], path[1]), amountIn);\n _swapSupportingFeeOnTransferTokens(path, address(this));\n uint256 amountOut = IERC20Joe(WAVAX).balanceOf(address(this));\n require(amountOut >= amountOutMin, \"JoeRouter: INSUFFICIENT_OUTPUT_AMOUNT\");\n IWAVAX(WAVAX).withdraw(amountOut);\n TransferHelper.safeTransferAVAX(to, amountOut);\n }\n\n // **** LIBRARY FUNCTIONS ****\n function quote(\n uint256 amountA,\n uint256 reserveA,\n uint256 reserveB\n ) public pure virtual override returns (uint256 amountB) {\n return JoeLibrary.quote(amountA, reserveA, reserveB);\n }\n\n function getAmountOut(\n uint256 amountIn,\n uint256 reserveIn,\n uint256 reserveOut\n ) public pure virtual override returns (uint256 amountOut) {\n return JoeLibrary.getAmountOut(amountIn, reserveIn, reserveOut);\n }\n\n function getAmountIn(\n uint256 amountOut,\n uint256 reserveIn,\n uint256 reserveOut\n ) public pure virtual override returns (uint256 amountIn) {\n return JoeLibrary.getAmountIn(amountOut, reserveIn, reserveOut);\n }\n\n function getAmountsOut(uint256 amountIn, address[] memory path)\n public\n view\n virtual\n override\n returns (uint256[] memory amounts)\n {\n return JoeLibrary.getAmountsOut(factory, amountIn, path);\n }\n\n function getAmountsIn(uint256 amountOut, address[] memory path)\n public\n view\n virtual\n override\n returns (uint256[] memory amounts)\n {\n return JoeLibrary.getAmountsIn(factory, amountOut, path);\n }\n}\n" + }, + "contracts/traderjoe/libraries/JoeLibrary.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\nimport \"../interfaces/IJoePair.sol\";\n\nimport \"./SafeMath.sol\";\n\nlibrary JoeLibrary {\n using SafeMathJoe for uint256;\n\n // returns sorted token addresses, used to handle return values from pairs sorted in this order\n function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {\n require(tokenA != tokenB, \"JoeLibrary: IDENTICAL_ADDRESSES\");\n (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);\n require(token0 != address(0), \"JoeLibrary: ZERO_ADDRESS\");\n }\n\n // calculates the CREATE2 address for a pair without making any external calls\n function pairFor(\n address factory,\n address tokenA,\n address tokenB\n ) internal pure returns (address pair) {\n (address token0, address token1) = sortTokens(tokenA, tokenB);\n pair = address(\n uint256(\n keccak256(\n abi.encodePacked(\n hex\"ff\",\n factory,\n keccak256(abi.encodePacked(token0, token1)),\n hex\"0bbca9af0511ad1a1da383135cf3a8d2ac620e549ef9f6ae3a4c33c2fed0af91\" // init code fuji\n )\n )\n )\n );\n }\n\n // fetches and sorts the reserves for a pair\n function getReserves(\n address factory,\n address tokenA,\n address tokenB\n ) internal view returns (uint256 reserveA, uint256 reserveB) {\n (address token0, ) = sortTokens(tokenA, tokenB);\n (uint256 reserve0, uint256 reserve1, ) = IJoePair(pairFor(factory, tokenA, tokenB)).getReserves();\n (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);\n }\n\n // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset\n function quote(\n uint256 amountA,\n uint256 reserveA,\n uint256 reserveB\n ) internal pure returns (uint256 amountB) {\n require(amountA > 0, \"JoeLibrary: INSUFFICIENT_AMOUNT\");\n require(reserveA > 0 && reserveB > 0, \"JoeLibrary: INSUFFICIENT_LIQUIDITY\");\n amountB = amountA.mul(reserveB) / reserveA;\n }\n\n // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset\n function getAmountOut(\n uint256 amountIn,\n uint256 reserveIn,\n uint256 reserveOut\n ) internal pure returns (uint256 amountOut) {\n require(amountIn > 0, \"JoeLibrary: INSUFFICIENT_INPUT_AMOUNT\");\n require(reserveIn > 0 && reserveOut > 0, \"JoeLibrary: INSUFFICIENT_LIQUIDITY\");\n uint256 amountInWithFee = amountIn.mul(997);\n uint256 numerator = amountInWithFee.mul(reserveOut);\n uint256 denominator = reserveIn.mul(1000).add(amountInWithFee);\n amountOut = numerator / denominator;\n }\n\n // given an output amount of an asset and pair reserves, returns a required input amount of the other asset\n function getAmountIn(\n uint256 amountOut,\n uint256 reserveIn,\n uint256 reserveOut\n ) internal pure returns (uint256 amountIn) {\n require(amountOut > 0, \"JoeLibrary: INSUFFICIENT_OUTPUT_AMOUNT\");\n require(reserveIn > 0 && reserveOut > 0, \"JoeLibrary: INSUFFICIENT_LIQUIDITY\");\n uint256 numerator = reserveIn.mul(amountOut).mul(1000);\n uint256 denominator = reserveOut.sub(amountOut).mul(997);\n amountIn = (numerator / denominator).add(1);\n }\n\n // performs chained getAmountOut calculations on any number of pairs\n function getAmountsOut(\n address factory,\n uint256 amountIn,\n address[] memory path\n ) internal view returns (uint256[] memory amounts) {\n require(path.length >= 2, \"JoeLibrary: INVALID_PATH\");\n amounts = new uint256[](path.length);\n amounts[0] = amountIn;\n for (uint256 i; i < path.length - 1; i++) {\n (uint256 reserveIn, uint256 reserveOut) = getReserves(factory, path[i], path[i + 1]);\n amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);\n }\n }\n\n // performs chained getAmountIn calculations on any number of pairs\n function getAmountsIn(\n address factory,\n uint256 amountOut,\n address[] memory path\n ) internal view returns (uint256[] memory amounts) {\n require(path.length >= 2, \"JoeLibrary: INVALID_PATH\");\n amounts = new uint256[](path.length);\n amounts[amounts.length - 1] = amountOut;\n for (uint256 i = path.length - 1; i > 0; i--) {\n (uint256 reserveIn, uint256 reserveOut) = getReserves(factory, path[i - 1], path[i]);\n amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);\n }\n }\n}\n" + }, + "contracts/traderjoe/libraries/TransferHelper.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.6.0;\n\n// helper methods for interacting with ERC20 tokens and sending AVAX that do not consistently return true/false\nlibrary TransferHelper {\n function safeApprove(\n address token,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('approve(address,uint256)')));\n (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"TransferHelper: APPROVE_FAILED\");\n }\n\n function safeTransfer(\n address token,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('transfer(address,uint256)')));\n (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"TransferHelper: TRANSFER_FAILED\");\n }\n\n function safeTransferFrom(\n address token,\n address from,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));\n (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"TransferHelper: TRANSFER_FROM_FAILED\");\n }\n\n function safeTransferAVAX(address to, uint256 value) internal {\n (bool success, ) = to.call{value: value}(new bytes(0));\n require(success, \"TransferHelper: AVAX_TRANSFER_FAILED\");\n }\n}\n" + }, + "contracts/traderjoe/interfaces/IJoeRouter02.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.6.2;\n\nimport \"./IJoeRouter01.sol\";\n\ninterface IJoeRouter02 is IJoeRouter01 {\n function removeLiquidityAVAXSupportingFeeOnTransferTokens(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline\n ) external returns (uint256 amountAVAX);\n\n function removeLiquidityAVAXWithPermitSupportingFeeOnTransferTokens(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline,\n bool approveMax,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external returns (uint256 amountAVAX);\n\n function swapExactTokensForTokensSupportingFeeOnTransferTokens(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external;\n\n function swapExactAVAXForTokensSupportingFeeOnTransferTokens(\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external payable;\n\n function swapExactTokensForAVAXSupportingFeeOnTransferTokens(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external;\n}\n" + }, + "contracts/traderjoe/interfaces/IWAVAX.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\ninterface IWAVAX {\n function deposit() external payable;\n\n function transfer(address to, uint256 value) external returns (bool);\n\n function withdraw(uint256) external;\n}\n" + }, + "contracts/traderjoe/interfaces/IJoePair.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\ninterface IJoePair {\n event Approval(address indexed owner, address indexed spender, uint256 value);\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n function name() external pure returns (string memory);\n\n function symbol() external pure returns (string memory);\n\n function decimals() external pure returns (uint8);\n\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address owner) external view returns (uint256);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 value) external returns (bool);\n\n function transfer(address to, uint256 value) external returns (bool);\n\n function transferFrom(\n address from,\n address to,\n uint256 value\n ) external returns (bool);\n\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n\n function PERMIT_TYPEHASH() external pure returns (bytes32);\n\n function nonces(address owner) external view returns (uint256);\n\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n\n event Mint(address indexed sender, uint256 amount0, uint256 amount1);\n event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);\n event Swap(\n address indexed sender,\n uint256 amount0In,\n uint256 amount1In,\n uint256 amount0Out,\n uint256 amount1Out,\n address indexed to\n );\n event Sync(uint112 reserve0, uint112 reserve1);\n\n function MINIMUM_LIQUIDITY() external pure returns (uint256);\n\n function factory() external view returns (address);\n\n function token0() external view returns (address);\n\n function token1() external view returns (address);\n\n function getReserves()\n external\n view\n returns (\n uint112 reserve0,\n uint112 reserve1,\n uint32 blockTimestampLast\n );\n\n function price0CumulativeLast() external view returns (uint256);\n\n function price1CumulativeLast() external view returns (uint256);\n\n function kLast() external view returns (uint256);\n\n function mint(address to) external returns (uint256 liquidity);\n\n function burn(address to) external returns (uint256 amount0, uint256 amount1);\n\n function swap(\n uint256 amount0Out,\n uint256 amount1Out,\n address to,\n bytes calldata data\n ) external;\n\n function skim(address to) external;\n\n function sync() external;\n\n function initialize(address, address) external;\n}\n" + }, + "contracts/traderjoe/interfaces/IJoeRouter01.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.6.2;\n\ninterface IJoeRouter01 {\n function factory() external pure returns (address);\n\n function WAVAX() external pure returns (address);\n\n function addLiquidity(\n address tokenA,\n address tokenB,\n uint256 amountADesired,\n uint256 amountBDesired,\n uint256 amountAMin,\n uint256 amountBMin,\n address to,\n uint256 deadline\n )\n external\n returns (\n uint256 amountA,\n uint256 amountB,\n uint256 liquidity\n );\n\n function addLiquidityAVAX(\n address token,\n uint256 amountTokenDesired,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline\n )\n external\n payable\n returns (\n uint256 amountToken,\n uint256 amountAVAX,\n uint256 liquidity\n );\n\n function removeLiquidity(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n address to,\n uint256 deadline\n ) external returns (uint256 amountA, uint256 amountB);\n\n function removeLiquidityAVAX(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline\n ) external returns (uint256 amountToken, uint256 amountAVAX);\n\n function removeLiquidityWithPermit(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n address to,\n uint256 deadline,\n bool approveMax,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external returns (uint256 amountA, uint256 amountB);\n\n function removeLiquidityAVAXWithPermit(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline,\n bool approveMax,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external returns (uint256 amountToken, uint256 amountAVAX);\n\n function swapExactTokensForTokens(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external returns (uint256[] memory amounts);\n\n function swapTokensForExactTokens(\n uint256 amountOut,\n uint256 amountInMax,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external returns (uint256[] memory amounts);\n\n function swapExactAVAXForTokens(\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external payable returns (uint256[] memory amounts);\n\n function swapTokensForExactAVAX(\n uint256 amountOut,\n uint256 amountInMax,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external returns (uint256[] memory amounts);\n\n function swapExactTokensForAVAX(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external returns (uint256[] memory amounts);\n\n function swapAVAXForExactTokens(\n uint256 amountOut,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external payable returns (uint256[] memory amounts);\n\n function quote(\n uint256 amountA,\n uint256 reserveA,\n uint256 reserveB\n ) external pure returns (uint256 amountB);\n\n function getAmountOut(\n uint256 amountIn,\n uint256 reserveIn,\n uint256 reserveOut\n ) external pure returns (uint256 amountOut);\n\n function getAmountIn(\n uint256 amountOut,\n uint256 reserveIn,\n uint256 reserveOut\n ) external pure returns (uint256 amountIn);\n\n function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts);\n\n function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts);\n}\n" + }, + "contracts/Zap.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity =0.6.12;\n\n/*\n * Trader Joe\n * MIT License; modified from PancakeBunny\n *\n */\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\n\nimport \"./traderjoe/interfaces/IJoePair.sol\";\nimport \"./traderjoe/interfaces/IJoeRouter02.sol\";\nimport \"./traderjoe/interfaces/IWAVAX.sol\";\n\ncontract Zap is OwnableUpgradeable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n /* ========== CONSTANT VARIABLES ========== */\n\n address public JOE;\n address public constant USDT = 0xde3A24028580884448a5397872046a019649b084;\n address public constant DAI = 0xbA7dEebBFC5fA1100Fb055a87773e1E99Cd3507a;\n address public constant WAVAX = 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7;\n\n IJoeRouter02 private ROUTER;\n\n /* ========== STATE VARIABLES ========== */\n\n mapping(address => bool) private notLP;\n mapping(address => address) private routePairAddresses;\n address[] public tokens;\n\n /* ========== INITIALIZER ========== */\n\n function initialize(address _joe, address _router) external initializer {\n __Ownable_init();\n require(owner() != address(0), \"ZapETH: owner must be set\");\n\n JOE = _joe;\n ROUTER = IJoeRouter02(_router);\n setNotLP(WAVAX);\n setNotLP(USDT);\n setNotLP(JOE);\n setNotLP(DAI);\n }\n\n receive() external payable {}\n\n /* ========== View Functions ========== */\n\n function isLP(address _address) public view returns (bool) {\n return !notLP[_address];\n }\n\n function routePair(address _address) external view returns (address) {\n return routePairAddresses[_address];\n }\n\n /* ========== External Functions ========== */\n\n function zapInToken(\n address _from,\n uint256 amount,\n address _to\n ) external {\n IERC20(_from).safeTransferFrom(msg.sender, address(this), amount);\n _approveTokenIfNeeded(_from);\n\n if (isLP(_to)) {\n IJoePair pair = IJoePair(_to);\n address token0 = pair.token0();\n address token1 = pair.token1();\n if (_from == token0 || _from == token1) {\n // swap half amount for other\n address other = _from == token0 ? token1 : token0;\n _approveTokenIfNeeded(other);\n uint256 sellAmount = amount.div(2);\n uint256 otherAmount = _swap(_from, sellAmount, other, address(this));\n ROUTER.addLiquidity(\n _from,\n other,\n amount.sub(sellAmount),\n otherAmount,\n 0,\n 0,\n msg.sender,\n block.timestamp\n );\n } else {\n uint256 avaxAmount = _swapTokenForAVAX(_from, amount, address(this));\n _swapAVAXToLP(_to, avaxAmount, msg.sender);\n }\n } else {\n _swap(_from, amount, _to, msg.sender);\n }\n }\n\n function zapIn(address _to) external payable {\n _swapAVAXToLP(_to, msg.value, msg.sender);\n }\n\n function zapOut(address _from, uint256 amount) external {\n IERC20(_from).safeTransferFrom(msg.sender, address(this), amount);\n _approveTokenIfNeeded(_from);\n\n if (!isLP(_from)) {\n _swapTokenForAVAX(_from, amount, msg.sender);\n } else {\n IJoePair pair = IJoePair(_from);\n address token0 = pair.token0();\n address token1 = pair.token1();\n if (token0 == WAVAX || token1 == WAVAX) {\n ROUTER.removeLiquidityAVAX(\n token0 != WAVAX ? token0 : token1,\n amount,\n 0,\n 0,\n msg.sender,\n block.timestamp\n );\n } else {\n ROUTER.removeLiquidity(token0, token1, amount, 0, 0, msg.sender, block.timestamp);\n }\n }\n }\n\n /* ========== Private Functions ========== */\n\n function _approveTokenIfNeeded(address token) private {\n if (IERC20(token).allowance(address(this), address(ROUTER)) == 0) {\n IERC20(token).safeApprove(address(ROUTER), uint256(~0));\n }\n }\n\n function _swapAVAXToLP(\n address lp,\n uint256 amount,\n address receiver\n ) private {\n if (!isLP(lp)) {\n _swapAVAXForToken(lp, amount, receiver);\n } else {\n // lp\n IJoePair pair = IJoePair(lp);\n address token0 = pair.token0();\n address token1 = pair.token1();\n if (token0 == WAVAX || token1 == WAVAX) {\n address token = token0 == WAVAX ? token1 : token0;\n uint256 swapValue = amount.div(2);\n uint256 tokenAmount = _swapAVAXForToken(token, swapValue, address(this));\n\n _approveTokenIfNeeded(token);\n ROUTER.addLiquidityAVAX{value: amount.sub(swapValue)}(\n token,\n tokenAmount,\n 0,\n 0,\n receiver,\n block.timestamp\n );\n } else {\n uint256 swapValue = amount.div(2);\n uint256 token0Amount = _swapAVAXForToken(token0, swapValue, address(this));\n uint256 token1Amount = _swapAVAXForToken(token1, amount.sub(swapValue), address(this));\n\n _approveTokenIfNeeded(token0);\n _approveTokenIfNeeded(token1);\n ROUTER.addLiquidity(token0, token1, token0Amount, token1Amount, 0, 0, receiver, block.timestamp);\n }\n }\n }\n\n function _swapAVAXForToken(\n address token,\n uint256 value,\n address receiver\n ) private returns (uint256) {\n address[] memory path;\n\n if (routePairAddresses[token] != address(0)) {\n path = new address[](3);\n path[0] = WAVAX;\n path[1] = routePairAddresses[token];\n path[2] = token;\n } else {\n path = new address[](2);\n path[0] = WAVAX;\n path[1] = token;\n }\n\n uint256[] memory amounts = ROUTER.swapExactAVAXForTokens{value: value}(0, path, receiver, block.timestamp);\n return amounts[amounts.length - 1];\n }\n\n function _swapTokenForAVAX(\n address token,\n uint256 amount,\n address receiver\n ) private returns (uint256) {\n address[] memory path;\n if (routePairAddresses[token] != address(0)) {\n path = new address[](3);\n path[0] = token;\n path[1] = routePairAddresses[token];\n path[2] = WAVAX;\n } else {\n path = new address[](2);\n path[0] = token;\n path[1] = WAVAX;\n }\n\n uint256[] memory amounts = ROUTER.swapExactTokensForAVAX(amount, 0, path, receiver, block.timestamp);\n return amounts[amounts.length - 1];\n }\n\n function _swap(\n address _from,\n uint256 amount,\n address _to,\n address receiver\n ) private returns (uint256) {\n address intermediate = routePairAddresses[_from];\n if (intermediate == address(0)) {\n intermediate = routePairAddresses[_to];\n }\n\n address[] memory path;\n if (intermediate != address(0) && (_from == WAVAX || _to == WAVAX)) {\n // [WAVAX, BUSD, VAI] or [VAI, BUSD, WAVAX]\n path = new address[](3);\n path[0] = _from;\n path[1] = intermediate;\n path[2] = _to;\n } else if (intermediate != address(0) && (_from == intermediate || _to == intermediate)) {\n // [VAI, BUSD] or [BUSD, VAI]\n path = new address[](2);\n path[0] = _from;\n path[1] = _to;\n } else if (intermediate != address(0) && routePairAddresses[_from] == routePairAddresses[_to]) {\n // [VAI, DAI] or [VAI, USDC]\n path = new address[](3);\n path[0] = _from;\n path[1] = intermediate;\n path[2] = _to;\n } else if (\n routePairAddresses[_from] != address(0) &&\n routePairAddresses[_to] != address(0) &&\n routePairAddresses[_from] != routePairAddresses[_to]\n ) {\n // routePairAddresses[xToken] = xRoute\n // [VAI, BUSD, WAVAX, xRoute, xToken]\n path = new address[](5);\n path[0] = _from;\n path[1] = routePairAddresses[_from];\n path[2] = WAVAX;\n path[3] = routePairAddresses[_to];\n path[4] = _to;\n } else if (intermediate != address(0) && routePairAddresses[_from] != address(0)) {\n // [VAI, BUSD, WAVAX, BUNNY]\n path = new address[](4);\n path[0] = _from;\n path[1] = intermediate;\n path[2] = WAVAX;\n path[3] = _to;\n } else if (intermediate != address(0) && routePairAddresses[_to] != address(0)) {\n // [BUNNY, WAVAX, BUSD, VAI]\n path = new address[](4);\n path[0] = _from;\n path[1] = WAVAX;\n path[2] = intermediate;\n path[3] = _to;\n } else if (_from == WAVAX || _to == WAVAX) {\n // [WAVAX, BUNNY] or [BUNNY, WAVAX]\n path = new address[](2);\n path[0] = _from;\n path[1] = _to;\n } else {\n // [USDT, BUNNY] or [BUNNY, USDT]\n path = new address[](3);\n path[0] = _from;\n path[1] = WAVAX;\n path[2] = _to;\n }\n\n uint256[] memory amounts = ROUTER.swapExactTokensForTokens(amount, 0, path, receiver, block.timestamp);\n return amounts[amounts.length - 1];\n }\n\n /* ========== RESTRICTED FUNCTIONS ========== */\n\n function setRoutePairAddress(address asset, address route) external onlyOwner {\n routePairAddresses[asset] = route;\n }\n\n function setNotLP(address token) public onlyOwner {\n bool needPush = notLP[token] == false;\n notLP[token] = true;\n if (needPush) {\n tokens.push(token);\n }\n }\n\n function removeToken(uint256 i) external onlyOwner {\n address token = tokens[i];\n notLP[token] = false;\n tokens[i] = tokens[tokens.length - 1];\n tokens.pop();\n }\n\n function sweep() external onlyOwner {\n for (uint256 i = 0; i < tokens.length; i++) {\n address token = tokens[i];\n if (token == address(0)) continue;\n uint256 amount = IERC20(token).balanceOf(address(this));\n if (amount > 0) {\n if (token == WAVAX) {\n IWAVAX(token).withdraw(amount);\n } else {\n _swapTokenForAVAX(token, amount, owner());\n }\n }\n }\n\n uint256 balance = address(this).balance;\n if (balance > 0) {\n payable(owner()).transfer(balance);\n }\n }\n\n function withdraw(address token) external onlyOwner {\n if (token == address(0)) {\n payable(owner()).transfer(address(this).balance);\n return;\n }\n\n IERC20(token).transfer(owner(), IERC20(token).balanceOf(address(this)));\n }\n}\n" + }, + "@openzeppelin/contracts/math/SafeMath.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMath {\n /**\n * @dev Returns the addition of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n uint256 c = a + b;\n if (c < a) return (false, 0);\n return (true, c);\n }\n\n /**\n * @dev Returns the substraction of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n if (b > a) return (false, 0);\n return (true, a - b);\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) return (true, 0);\n uint256 c = a * b;\n if (c / a != b) return (false, 0);\n return (true, c);\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a division by zero flag.\n *\n * _Available since v3.4._\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n if (b == 0) return (false, 0);\n return (true, a / b);\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\n *\n * _Available since v3.4._\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n if (b == 0) return (false, 0);\n return (true, a % b);\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n *\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b <= a, \"SafeMath: subtraction overflow\");\n return a - b;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n *\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n if (a == 0) return 0;\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers, reverting on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b > 0, \"SafeMath: division by zero\");\n return a / b;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * reverting when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b > 0, \"SafeMath: modulo by zero\");\n return a % b;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n * overflow (when the result is negative).\n *\n * CAUTION: This function is deprecated because it requires allocating memory for the error\n * message unnecessarily. For custom revert reasons use {trySub}.\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b <= a, errorMessage);\n return a - b;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers, reverting with custom message on\n * division by zero. The result is rounded towards zero.\n *\n * CAUTION: This function is deprecated because it requires allocating memory for the error\n * message unnecessarily. For custom revert reasons use {tryDiv}.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b > 0, errorMessage);\n return a / b;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * reverting with custom message when dividing by zero.\n *\n * CAUTION: This function is deprecated because it requires allocating memory for the error\n * message unnecessarily. For custom revert reasons use {tryMod}.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b > 0, errorMessage);\n return a % b;\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/SafeERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"../../math/SafeMath.sol\";\nimport \"../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using SafeMath for uint256;\n using Address for address;\n\n function safeTransfer(IERC20 token, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {IERC20-approve}, and its usage is discouraged.\n *\n * Whenever possible, use {safeIncreaseAllowance} and\n * {safeDecreaseAllowance} instead.\n */\n function safeApprove(IERC20 token, address spender, uint256 value) internal {\n // safeApprove should only be called when setting an initial allowance,\n // or when resetting it to zero. To increase and decrease it, use\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n // solhint-disable-next-line max-line-length\n require((value == 0) || (token.allowance(address(this), spender) == 0),\n \"SafeERC20: approve from non-zero to non-zero allowance\"\n );\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 newAllowance = token.allowance(address(this), spender).add(value);\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 newAllowance = token.allowance(address(this), spender).sub(value, \"SafeERC20: decreased allowance below zero\");\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n if (returndata.length > 0) { // Return data is optional\n // solhint-disable-next-line max-line-length\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `recipient`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address recipient, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `sender` to `recipient` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n" + }, + "@openzeppelin/contracts/utils/Address.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.2 <0.8.0;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize, which returns 0 for contracts in\n // construction, since the code is only stored at the end of the\n // constructor execution.\n\n uint256 size;\n // solhint-disable-next-line no-inline-assembly\n assembly { size := extcodesize(account) }\n return size > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\n (bool success, ) = recipient.call{ value: amount }(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain`call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, bytes memory returndata) = target.call{ value: value }(data);\n return _verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, bytes memory returndata) = target.staticcall(data);\n return _verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return _verifyCallResult(success, returndata, errorMessage);\n }\n\n function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n\n // solhint-disable-next-line no-inline-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n" + }, + "contracts/JoeRoll.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./traderjoe/interfaces/IJoePair.sol\";\nimport \"./traderjoe/interfaces/IJoeRouter01.sol\";\nimport \"./traderjoe/interfaces/IJoeFactory.sol\";\nimport \"./traderjoe/libraries/JoeLibrary.sol\";\n\n// JoeRoll helps your migrate your existing Uniswap LP tokens to TraderJoe LP ones\ncontract JoeRoll is Ownable {\n using SafeERC20 for IERC20;\n\n IJoeRouter01 public oldRouter;\n IJoeRouter01 public router;\n IERC20 public hatToken = IERC20(0x82FE038Ea4b50f9C957da326C412ebd73462077C);\n\n constructor(IJoeRouter01 _oldRouter, IJoeRouter01 _router) public {\n oldRouter = _oldRouter;\n router = _router;\n }\n\n function migrateWithPermit(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) public {\n IJoePair pair = IJoePair(pairForOldRouter(tokenA, tokenB));\n pair.permit(msg.sender, address(this), liquidity, deadline, v, r, s);\n\n migrate(tokenA, tokenB, liquidity, amountAMin, amountBMin, deadline);\n }\n\n // msg.sender should have approved 'liquidity' amount of LP token of 'tokenA' and 'tokenB'\n function migrate(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n uint256 deadline\n ) public {\n require(deadline >= block.timestamp, \"JoeSwap: EXPIRED\");\n\n // Remove liquidity from the old router with permit\n (uint256 amountA, uint256 amountB) = removeLiquidity(\n tokenA,\n tokenB,\n liquidity,\n amountAMin,\n amountBMin,\n deadline\n );\n\n // Add liquidity to the new router\n (uint256 pooledAmountA, uint256 pooledAmountB) = addLiquidity(tokenA, tokenB, amountA, amountB);\n\n // Send remaining tokens to msg.sender\n if (amountA > pooledAmountA) {\n IERC20(tokenA).safeTransfer(msg.sender, amountA - pooledAmountA);\n }\n if (amountB > pooledAmountB) {\n IERC20(tokenB).safeTransfer(msg.sender, amountB - pooledAmountB);\n }\n\n // Transfer user a single hat token if there are any remaining and user has not received one yet\n if (address(hatToken) != address(0)) {\n uint256 hatSupply = hatToken.balanceOf(address(this));\n uint256 userSupply = hatToken.balanceOf(msg.sender);\n if (hatSupply > 0 && userSupply == 0) {\n hatToken.safeTransfer(msg.sender, 1e18);\n }\n }\n }\n\n function removeLiquidity(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n uint256 deadline\n ) internal returns (uint256 amountA, uint256 amountB) {\n IJoePair pair = IJoePair(pairForOldRouter(tokenA, tokenB));\n pair.transferFrom(msg.sender, address(pair), liquidity);\n (uint256 amount0, uint256 amount1) = pair.burn(address(this));\n (address token0, ) = JoeLibrary.sortTokens(tokenA, tokenB);\n (amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0);\n require(amountA >= amountAMin, \"JoeRoll: INSUFFICIENT_A_AMOUNT\");\n require(amountB >= amountBMin, \"JoeRoll: INSUFFICIENT_B_AMOUNT\");\n }\n\n // calculates the CREATE2 address for a pair without making any external calls\n function pairForOldRouter(address tokenA, address tokenB) internal view returns (address pair) {\n (address token0, address token1) = JoeLibrary.sortTokens(tokenA, tokenB);\n pair = address(\n uint256(\n keccak256(\n abi.encodePacked(\n hex\"ff\",\n oldRouter.factory(),\n keccak256(abi.encodePacked(token0, token1)),\n hex\"40231f6b438bce0797c9ada29b718a87ea0a5cea3fe9a771abdd76bd41a3e545\" // init code hash\n )\n )\n )\n );\n }\n\n function addLiquidity(\n address tokenA,\n address tokenB,\n uint256 amountADesired,\n uint256 amountBDesired\n ) internal returns (uint256 amountA, uint256 amountB) {\n (amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired);\n address pair = JoeLibrary.pairFor(router.factory(), tokenA, tokenB);\n IERC20(tokenA).safeTransfer(pair, amountA);\n IERC20(tokenB).safeTransfer(pair, amountB);\n IJoePair(pair).mint(msg.sender);\n }\n\n function _addLiquidity(\n address tokenA,\n address tokenB,\n uint256 amountADesired,\n uint256 amountBDesired\n ) internal returns (uint256 amountA, uint256 amountB) {\n // create the pair if it doesn't exist yet\n IJoeFactory factory = IJoeFactory(router.factory());\n if (factory.getPair(tokenA, tokenB) == address(0)) {\n factory.createPair(tokenA, tokenB);\n }\n (uint256 reserveA, uint256 reserveB) = JoeLibrary.getReserves(address(factory), tokenA, tokenB);\n if (reserveA == 0 && reserveB == 0) {\n (amountA, amountB) = (amountADesired, amountBDesired);\n } else {\n uint256 amountBOptimal = JoeLibrary.quote(amountADesired, reserveA, reserveB);\n if (amountBOptimal <= amountBDesired) {\n (amountA, amountB) = (amountADesired, amountBOptimal);\n } else {\n uint256 amountAOptimal = JoeLibrary.quote(amountBDesired, reserveB, reserveA);\n assert(amountAOptimal <= amountADesired);\n (amountA, amountB) = (amountAOptimal, amountBDesired);\n }\n }\n }\n}\n" + }, + "@openzeppelin/contracts/access/Ownable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../utils/Context.sol\";\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor () internal {\n address msgSender = _msgSender();\n _owner = msgSender;\n emit OwnershipTransferred(address(0), msgSender);\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n _;\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n emit OwnershipTransferred(_owner, address(0));\n _owner = address(0);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n emit OwnershipTransferred(_owner, newOwner);\n _owner = newOwner;\n }\n}\n" + }, + "@openzeppelin/contracts/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/*\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with GSN meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address payable) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes memory) {\n this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n return msg.data;\n }\n}\n" + }, + "contracts/MoneyMaker.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// P1 - P3: OK\npragma solidity 0.6.12;\n\nimport \"./libraries/SafeMath.sol\";\nimport \"./libraries/SafeERC20.sol\";\n\nimport \"./traderjoe/interfaces/IERC20.sol\";\nimport \"./traderjoe/interfaces/IJoePair.sol\";\nimport \"./traderjoe/interfaces/IJoeFactory.sol\";\nimport \"./traderjoe/libraries/JoeLibrary.sol\";\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/utils/EnumerableSet.sol\";\n\n/// @title Money Maker\n/// @author Trader Joe\n/// @notice MoneyMaker receives 0.05% of the swaps done on Trader Joe in the form of an LP. It swaps those LPs\n/// to a token of choice and sends it to the JoeBar\ncontract MoneyMaker is Ownable {\n using EnumerableSet for EnumerableSet.AddressSet;\n using SafeERC20 for IERC20;\n using SafeMath for uint256;\n\n IJoeFactory public immutable factory;\n\n address public immutable bar;\n address private immutable wavax;\n /// @notice Any ERC20\n address public tokenTo;\n /// @notice In basis points aka parts per 10,000 so 5000 is 50%, cap of 50%, default is 0\n uint256 public devCut = 0;\n address public devAddr;\n\n // @notice Set of addresses that can perform certain functions\n EnumerableSet.AddressSet private _isAuth;\n\n modifier onlyAuth() {\n require(_isAuth.contains(_msgSender()), \"MoneyMaker: FORBIDDEN\");\n _;\n }\n\n /// @dev Maps a token `token` to another token `bridge` so that it uses `token/bridge` pair to convert token\n mapping(address => address) internal _bridges;\n\n event AddAuthorizedAddress(address indexed _addr);\n event RemoveAuthorizedAddress(address indexed _addr);\n event SetDevAddr(address _addr);\n event SetDevCut(uint256 _amount);\n event SetTokenTo(address _tokenTo);\n event LogBridgeSet(address indexed token, address indexed oldBridge, address indexed bridge);\n event LogConvert(\n address indexed server,\n address indexed token0,\n address indexed token1,\n uint256 amount0,\n uint256 amount1,\n uint256 amountTOKEN\n );\n\n /// @notice Constructor\n /// @param _factory The address of JoeFactory\n /// @param _bar The address of JoeBar\n /// @param _tokenTo The address of the token we want to convert to\n /// @param _wavax The address of wavax\n constructor(\n address _factory,\n address _bar,\n address _tokenTo,\n address _wavax\n ) public {\n require(_factory != address(0), \"MoneyMaker: factory can't be address(0)\");\n require(_bar != address(0), \"MoneyMaker: bar can't be address(0)\");\n require(_tokenTo != address(0), \"MoneyMaker: token can't be address(0)\");\n require(_wavax != address(0), \"MoneyMaker: wavax can't be address(0)\");\n factory = IJoeFactory(_factory);\n bar = _bar;\n tokenTo = _tokenTo;\n wavax = _wavax;\n devAddr = _msgSender();\n _isAuth.add(_msgSender());\n }\n\n /// @notice Adds a user to the authorized addresses\n /// @param _auth The address to add\n function addAuth(address _auth) external onlyOwner {\n require(_isAuth.add(_auth), \"MoneyMaker: Address is already authorized\");\n emit AddAuthorizedAddress(_auth);\n }\n\n /// @notice Remove a user of authorized addresses\n /// @param _auth The address to remove\n function removeAuth(address _auth) external onlyOwner {\n require(_isAuth.remove(_auth), \"MoneyMaker: Address is not authorized\");\n emit RemoveAuthorizedAddress(_auth);\n }\n\n /// @notice Return the list of authorized addresses\n /// @param index Index of the returned address\n /// @return The authorized address at `index`\n function getAuth(uint256 index) external view returns (address) {\n return _isAuth.at(index);\n }\n\n /// @notice Return the length of authorized addresses\n /// @return The number of authorized addresses\n function lenAuth() external view returns (uint256) {\n return _isAuth.length();\n }\n\n /// @notice Force using `pair/bridge` pair to convert `token`\n /// @param token The address of the tokenFrom\n /// @param bridge The address of the tokenTo\n function setBridge(address token, address bridge) external onlyAuth {\n // Checks\n require(token != tokenTo && token != wavax && token != bridge, \"MoneyMaker: Invalid bridge\");\n\n // Effects\n address oldBridge = _bridges[token];\n _bridges[token] = bridge;\n emit LogBridgeSet(token, oldBridge, bridge);\n }\n\n /// @notice Sets dev cut, which will be sent to `devAddr`, can't be greater than 50%\n /// @param _amount The new devCut value\n function setDevCut(uint256 _amount) external onlyOwner {\n require(_amount <= 5000, \"setDevCut: cut too high\");\n devCut = _amount;\n\n emit SetDevCut(_amount);\n }\n\n /// @notice Sets `devAddr`, the address that will receive the `devCut`\n /// @param _addr The new dev address\n function setDevAddr(address _addr) external onlyOwner {\n require(_addr != address(0), \"setDevAddr, address cannot be zero address\");\n devAddr = _addr;\n\n emit SetDevAddr(_addr);\n }\n\n /// @notice Sets token that we're buying back\n /// @param _tokenTo The new token address\n function setTokenToAddress(address _tokenTo) external onlyOwner {\n require(_tokenTo != address(0), \"setTokenToAddress, address cannot be zero address\");\n tokenTo = _tokenTo;\n\n emit SetTokenTo(_tokenTo);\n }\n\n /// @notice Returns the `bridge` of a `token`\n /// @param token The tokenFrom address\n /// @return bridge The tokenTo address\n function bridgeFor(address token) public view returns (address bridge) {\n bridge = _bridges[token];\n if (bridge == address(0)) {\n bridge = wavax;\n }\n }\n\n // C6: It's not a fool proof solution, but it prevents flash loans, so here it's ok to use tx.origin\n modifier onlyEOA() {\n // Try to make flash-loan exploit harder to do by only allowing externally owned addresses.\n require(_msgSender() == tx.origin, \"MoneyMaker: must use EOA\");\n _;\n }\n\n /// @notice Converts a pair of tokens to tokenTo\n /// @dev _convert is separate to save gas by only checking the 'onlyEOA' modifier once in case of convertMultiple\n /// @param token0 The address of the first token of the pair that will be converted\n /// @param token1 The address of the second token of the pair that will be converted\n /// @param slippage The accepted slippage, in basis points aka parts per 10,000 so 5000 is 50%\n function convert(\n address token0,\n address token1,\n uint256 slippage\n ) external onlyEOA onlyAuth {\n require(slippage < 5_000, \"MoneyMaker: slippage needs to be lower than 50%\");\n _convert(token0, token1, slippage);\n }\n\n /// @notice Converts a list of pairs of tokens to tokenTo\n /// @dev _convert is separate to save gas by only checking the 'onlyEOA' modifier once in case of convertMultiple\n /// @param token0 The list of addresses of the first token of the pairs that will be converted\n /// @param token1 The list of addresses of the second token of the pairs that will be converted\n /// @param slippage The accepted slippage, in basis points aka parts per 10,000 so 5000 is 50%\n function convertMultiple(\n address[] calldata token0,\n address[] calldata token1,\n uint256 slippage\n ) external onlyEOA onlyAuth {\n // TODO: This can be optimized a fair bit, but this is safer and simpler for now\n require(slippage < 5_000, \"MoneyMaker: slippage needs to be lower than 50%\");\n require(token0.length == token1.length, \"MoneyMaker: arrays length don't match\");\n\n uint256 len = token0.length;\n for (uint256 i = 0; i < len; i++) {\n _convert(token0[i], token1[i], slippage);\n }\n }\n\n /// @notice Converts a pair of tokens to tokenTo\n /// @dev _convert is separate to save gas by only checking the 'onlyEOA' modifier once in case of convertMultiple\n /// @param token0 The address of the first token of the pair that is currently being converted\n /// @param token1 The address of the second token of the pair that is currently being converted\n /// @param slippage The accepted slippage, in basis points aka parts per 10,000 so 5000 is 50%\n function _convert(\n address token0,\n address token1,\n uint256 slippage\n ) internal {\n uint256 amount0;\n uint256 amount1;\n\n // handle case where non-LP tokens need to be converted\n if (token0 == token1) {\n amount0 = IERC20(token0).balanceOf(address(this));\n amount1 = 0;\n } else {\n IJoePair pair = IJoePair(factory.getPair(token0, token1));\n require(address(pair) != address(0), \"MoneyMaker: Invalid pair\");\n\n IERC20(address(pair)).safeTransfer(address(pair), pair.balanceOf(address(this)));\n\n // take balance of tokens in this contract before burning the pair, incase there are already some here\n uint256 tok0bal = IERC20(token0).balanceOf(address(this));\n uint256 tok1bal = IERC20(token1).balanceOf(address(this));\n\n pair.burn(address(this));\n\n // subtract old balance of tokens from new balance\n // the return values of pair.burn cant be trusted due to transfer tax tokens\n amount0 = IERC20(token0).balanceOf(address(this)).sub(tok0bal);\n amount1 = IERC20(token1).balanceOf(address(this)).sub(tok1bal);\n }\n emit LogConvert(\n _msgSender(),\n token0,\n token1,\n amount0,\n amount1,\n _convertStep(token0, token1, amount0, amount1, slippage)\n );\n }\n\n /// @notice Used to convert two tokens to `tokenTo`, step by step, called recursively\n /// @param token0 The address of the first token\n /// @param token1 The address of the second token\n /// @param amount0 The amount of the `token0`\n /// @param amount1 The amount of the `token1`\n /// @param slippage The accepted slippage, in basis points aka parts per 10,000 so 5000 is 50%\n /// @return tokenOut The amount of token\n function _convertStep(\n address token0,\n address token1,\n uint256 amount0,\n uint256 amount1,\n uint256 slippage\n ) internal returns (uint256 tokenOut) {\n // Interactions\n if (token0 == token1) {\n uint256 amount = amount0.add(amount1);\n if (token0 == tokenTo) {\n IERC20(tokenTo).safeTransfer(bar, amount);\n tokenOut = amount;\n } else if (token0 == wavax) {\n tokenOut = _toToken(wavax, amount, slippage);\n } else {\n address bridge = bridgeFor(token0);\n amount = _swap(token0, bridge, amount, address(this), slippage);\n tokenOut = _convertStep(bridge, bridge, amount, 0, slippage);\n }\n } else if (token0 == tokenTo) {\n // eg. TOKEN - AVAX\n IERC20(tokenTo).safeTransfer(bar, amount0);\n tokenOut = _toToken(token1, amount1, slippage).add(amount0);\n } else if (token1 == tokenTo) {\n // eg. USDT - TOKEN\n IERC20(tokenTo).safeTransfer(bar, amount1);\n tokenOut = _toToken(token0, amount0, slippage).add(amount1);\n } else if (token0 == wavax) {\n // eg. AVAX - USDC\n tokenOut = _toToken(wavax, _swap(token1, wavax, amount1, address(this), slippage).add(amount0), slippage);\n } else if (token1 == wavax) {\n // eg. USDT - AVAX\n tokenOut = _toToken(wavax, _swap(token0, wavax, amount0, address(this), slippage).add(amount1), slippage);\n } else {\n // eg. MIC - USDT\n address bridge0 = bridgeFor(token0);\n address bridge1 = bridgeFor(token1);\n if (bridge0 == token1) {\n // eg. MIC - USDT - and bridgeFor(MIC) = USDT\n tokenOut = _convertStep(\n bridge0,\n token1,\n _swap(token0, bridge0, amount0, address(this), slippage),\n amount1,\n slippage\n );\n } else if (bridge1 == token0) {\n // eg. WBTC - DSD - and bridgeFor(DSD) = WBTC\n tokenOut = _convertStep(\n token0,\n bridge1,\n amount0,\n _swap(token1, bridge1, amount1, address(this), slippage),\n slippage\n );\n } else {\n tokenOut = _convertStep(\n bridge0,\n bridge1, // eg. USDT - DSD - and bridgeFor(DSD) = WBTC\n _swap(token0, bridge0, amount0, address(this), slippage),\n _swap(token1, bridge1, amount1, address(this), slippage),\n slippage\n );\n }\n }\n }\n\n /// @notice Swaps `amountIn` `fromToken` to `toToken` and sends it to `to`, `amountOut` is required to be greater\n /// than allowed `slippage`\n /// @param fromToken The address of token that will be swapped\n /// @param toToken The address of the token that will be received\n /// @param amountIn The amount of the `fromToken`\n /// @param to The address that will receive the `toToken`\n /// @param slippage The accepted slippage, in basis points aka parts per 10,000 so 5000 is 50%\n /// @return amountOut The amount of `toToken` sent to `to`\n function _swap(\n address fromToken,\n address toToken,\n uint256 amountIn,\n address to,\n uint256 slippage\n ) internal returns (uint256 amountOut) {\n // Checks\n // X1 - X5: OK\n IJoePair pair = IJoePair(factory.getPair(fromToken, toToken));\n require(address(pair) != address(0), \"MoneyMaker: Cannot convert\");\n\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n (uint256 reserveInput, uint256 reserveOutput) = fromToken == pair.token0()\n ? (reserve0, reserve1)\n : (reserve1, reserve0);\n IERC20(fromToken).safeTransfer(address(pair), amountIn);\n uint256 amountInput = IERC20(fromToken).balanceOf(address(pair)).sub(reserveInput); // calculate amount that was transferred, this accounts for transfer taxes\n\n amountOut = JoeLibrary.getAmountOut(amountInput, reserveInput, reserveOutput);\n\n {\n uint256 rest = uint256(10_000).sub(slippage);\n /// @dev We simulate the amount received if we did a swapIn and swapOut without updating the reserves,\n /// hence why we do rest^2, i.e. calculating the slippage twice cause we actually do two swaps.\n /// This allows us to catch if a pair has low liquidity\n require(\n JoeLibrary.getAmountOut(amountOut, reserveOutput, reserveInput) >=\n amountInput.mul(rest).mul(rest).div(100_000_000),\n \"MoneyMaker: Slippage caught\"\n );\n }\n\n (uint256 amount0Out, uint256 amount1Out) = fromToken == pair.token0()\n ? (uint256(0), amountOut)\n : (amountOut, uint256(0));\n pair.swap(amount0Out, amount1Out, to, new bytes(0));\n }\n\n /// @notice Swaps an amount of token to another token, `tokenTo`\n /// @dev `amountOut` is required to be greater after slippage\n /// @param token The address of token that will be swapped\n /// @param amountIn The amount of the `token`\n /// @param slippage The accepted slippage, in basis points aka parts per 10,000 so 5000 is 50%\n /// @return amountOut The amount of `toToken` sent to JoeBar\n function _toToken(\n address token,\n uint256 amountIn,\n uint256 slippage\n ) internal returns (uint256 amountOut) {\n uint256 amount = amountIn;\n if (devCut > 0) {\n amount = amount.mul(devCut).div(10000);\n IERC20(token).safeTransfer(devAddr, amount);\n amount = amountIn.sub(amount);\n }\n amountOut = _swap(token, tokenTo, amount, bar, slippage);\n }\n}\n" + }, + "contracts/libraries/SafeMath.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\n// a library for performing overflow-safe math, updated with awesomeness from of DappHub (https://github.com/dapphub/ds-math)\nlibrary SafeMath {\n function add(uint256 a, uint256 b) internal pure returns (uint256 c) {\n require((c = a + b) >= b, \"SafeMath: Add Overflow\");\n }\n\n function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {\n require((c = a - b) <= a, \"SafeMath: Underflow\");\n }\n\n function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {\n require(b == 0 || (c = a * b) / b == a, \"SafeMath: Mul Overflow\");\n }\n\n function div(uint256 a, uint256 b) internal pure returns (uint256 c) {\n require(b > 0, \"SafeMath: Div by Zero\");\n c = a / b;\n }\n\n function to128(uint256 a) internal pure returns (uint128 c) {\n require(a <= uint128(-1), \"SafeMath: uint128 Overflow\");\n c = uint128(a);\n }\n}\n\nlibrary SafeMath128 {\n function add(uint128 a, uint128 b) internal pure returns (uint128 c) {\n require((c = a + b) >= b, \"SafeMath: Add Overflow\");\n }\n\n function sub(uint128 a, uint128 b) internal pure returns (uint128 c) {\n require((c = a - b) <= a, \"SafeMath: Underflow\");\n }\n}\n" + }, + "contracts/libraries/SafeERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\nimport \"../interfaces/IERC20.sol\";\n\nlibrary SafeERC20 {\n function safeSymbol(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x95d89b41));\n return success && data.length > 0 ? abi.decode(data, (string)) : \"???\";\n }\n\n function safeName(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x06fdde03));\n return success && data.length > 0 ? abi.decode(data, (string)) : \"???\";\n }\n\n function safeDecimals(IERC20 token) internal view returns (uint8) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x313ce567));\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\n }\n\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(0xa9059cbb, to, amount));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"SafeERC20: Transfer failed\");\n }\n\n function safeTransferFrom(\n IERC20 token,\n address from,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(\n abi.encodeWithSelector(0x23b872dd, from, address(this), amount)\n );\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"SafeERC20: TransferFrom failed\");\n }\n}\n" + }, + "@openzeppelin/contracts/utils/EnumerableSet.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n * // Add the library methods\n * using EnumerableSet for EnumerableSet.AddressSet;\n *\n * // Declare a set state variable\n * EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n */\nlibrary EnumerableSet {\n // To implement this library for multiple types with as little code\n // repetition as possible, we write it in terms of a generic Set type with\n // bytes32 values.\n // The Set implementation uses private functions, and user-facing\n // implementations (such as AddressSet) are just wrappers around the\n // underlying Set.\n // This means that we can only create new EnumerableSets for types that fit\n // in bytes32.\n\n struct Set {\n // Storage of set values\n bytes32[] _values;\n\n // Position of the value in the `values` array, plus 1 because index 0\n // means a value is not in the set.\n mapping (bytes32 => uint256) _indexes;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function _add(Set storage set, bytes32 value) private returns (bool) {\n if (!_contains(set, value)) {\n set._values.push(value);\n // The value is stored at length-1, but we add 1 to all indexes\n // and use 0 as a sentinel value\n set._indexes[value] = set._values.length;\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function _remove(Set storage set, bytes32 value) private returns (bool) {\n // We read and store the value's index to prevent multiple reads from the same storage slot\n uint256 valueIndex = set._indexes[value];\n\n if (valueIndex != 0) { // Equivalent to contains(set, value)\n // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n // the array, and then remove the last element (sometimes called as 'swap and pop').\n // This modifies the order of the array, as noted in {at}.\n\n uint256 toDeleteIndex = valueIndex - 1;\n uint256 lastIndex = set._values.length - 1;\n\n // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs\n // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.\n\n bytes32 lastvalue = set._values[lastIndex];\n\n // Move the last value to the index where the value to delete is\n set._values[toDeleteIndex] = lastvalue;\n // Update the index for the moved value\n set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based\n\n // Delete the slot where the moved value was stored\n set._values.pop();\n\n // Delete the index for the deleted slot\n delete set._indexes[value];\n\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function _contains(Set storage set, bytes32 value) private view returns (bool) {\n return set._indexes[value] != 0;\n }\n\n /**\n * @dev Returns the number of values on the set. O(1).\n */\n function _length(Set storage set) private view returns (uint256) {\n return set._values.length;\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function _at(Set storage set, uint256 index) private view returns (bytes32) {\n require(set._values.length > index, \"EnumerableSet: index out of bounds\");\n return set._values[index];\n }\n\n // Bytes32Set\n\n struct Bytes32Set {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _add(set._inner, value);\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _remove(set._inner, value);\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n return _contains(set._inner, value);\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(Bytes32Set storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n return _at(set._inner, index);\n }\n\n // AddressSet\n\n struct AddressSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(AddressSet storage set, address value) internal returns (bool) {\n return _add(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(AddressSet storage set, address value) internal returns (bool) {\n return _remove(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(AddressSet storage set, address value) internal view returns (bool) {\n return _contains(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(AddressSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(AddressSet storage set, uint256 index) internal view returns (address) {\n return address(uint160(uint256(_at(set._inner, index))));\n }\n\n\n // UintSet\n\n struct UintSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(UintSet storage set, uint256 value) internal returns (bool) {\n return _add(set._inner, bytes32(value));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(UintSet storage set, uint256 value) internal returns (bool) {\n return _remove(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n return _contains(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns the number of values on the set. O(1).\n */\n function length(UintSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n return uint256(_at(set._inner, index));\n }\n}\n" + }, + "contracts/sushi/MasterChefPerSec.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/utils/EnumerableSet.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./SushiToken.sol\";\n\n// MasterChef is the master of Sushi. He can make Sushi and he is a fair guy.\n//\n// Note that it's ownable and the owner wields tremendous power. The ownership\n// will be transferred to a governance smart contract once SUSHI is sufficiently\n// distributed and the community can show to govern itself.\n//\n// Have fun reading it. Hopefully it's bug-free. God bless.\ncontract MasterChefPerSec is Ownable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n // Info of each user.\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n //\n // We do some fancy math here. Basically, any point in time, the amount of SUSHIs\n // entitled to a user but is pending to be distributed is:\n //\n // pending reward = (user.amount * pool.accSushiPerShare) - user.rewardDebt\n //\n // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:\n // 1. The pool's `accSushiPerShare` (and `lastRewardBlock`) gets updated.\n // 2. User receives the pending reward sent to his/her address.\n // 3. User's `amount` gets updated.\n // 4. User's `rewardDebt` gets updated.\n }\n // Info of each pool.\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. SUSHIs to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that SUSHIs distribution occurs.\n uint256 accSushiPerShare; // Accumulated SUSHIs per share, times 1e12. See below.\n }\n // The SUSHI TOKEN!\n SushiToken public sushi;\n // Dev address.\n address public devaddr;\n // Block number when bonus SUSHI period ends.\n uint256 public bonusEndTimestamp;\n // SUSHI tokens created per block.\n uint256 public sushiPerSec;\n // Bonus muliplier for early sushi makers.\n uint256 public constant BONUS_MULTIPLIER = 1;\n // Info of each pool.\n PoolInfo[] public poolInfo;\n // Info of each user that stakes LP tokens.\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n // Total allocation poitns. Must be the sum of all allocation points in all pools.\n uint256 public totalAllocPoint = 0;\n // The block number when SUSHI mining starts.\n uint256 public startTimestamp;\n event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\n event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\n\n constructor(\n SushiToken _sushi,\n address _devaddr,\n uint256 _sushiPerSec,\n uint256 _startTimestamp,\n uint256 _bonusEndTimestamp\n ) public {\n sushi = _sushi;\n devaddr = _devaddr;\n sushiPerSec = _sushiPerSec;\n bonusEndTimestamp = _bonusEndTimestamp;\n startTimestamp = _startTimestamp;\n }\n\n function poolLength() external view returns (uint256) {\n return poolInfo.length;\n }\n\n // Add a new lp to the pool. Can only be called by the owner.\n // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.\n function add(\n uint256 _allocPoint,\n IERC20 _lpToken,\n bool _withUpdate\n ) public onlyOwner {\n if (_withUpdate) {\n massUpdatePools();\n }\n uint256 lastRewardTimestamp = block.timestamp > startTimestamp ? block.timestamp : startTimestamp;\n totalAllocPoint = totalAllocPoint.add(_allocPoint);\n poolInfo.push(\n PoolInfo({\n lpToken: _lpToken,\n allocPoint: _allocPoint,\n lastRewardTimestamp: lastRewardTimestamp,\n accSushiPerShare: 0\n })\n );\n }\n\n // Update the given pool's SUSHI allocation point. Can only be called by the owner.\n function set(\n uint256 _pid,\n uint256 _allocPoint,\n bool _withUpdate\n ) public onlyOwner {\n if (_withUpdate) {\n massUpdatePools();\n }\n totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);\n poolInfo[_pid].allocPoint = _allocPoint;\n }\n\n // Return reward multiplier over the given _from to _to block.\n function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) {\n if (_to <= bonusEndTimestamp) {\n return _to.sub(_from).mul(BONUS_MULTIPLIER);\n } else if (_from >= bonusEndTimestamp) {\n return _to.sub(_from);\n } else {\n return bonusEndTimestamp.sub(_from).mul(BONUS_MULTIPLIER).add(_to.sub(bonusEndTimestamp));\n }\n }\n\n // View function to see pending SUSHIs on frontend.\n function pendingSushi(uint256 _pid, address _user) external view returns (uint256) {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_user];\n uint256 accSushiPerShare = pool.accSushiPerShare;\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (block.timestamp > pool.lastRewardTimestamp && lpSupply != 0) {\n uint256 multiplier = getMultiplier(pool.lastRewardTimestamp, block.timestamp);\n uint256 sushiReward = multiplier.mul(sushiPerSec).mul(pool.allocPoint).div(totalAllocPoint);\n accSushiPerShare = accSushiPerShare.add(sushiReward.mul(1e12).div(lpSupply));\n }\n return user.amount.mul(accSushiPerShare).div(1e12).sub(user.rewardDebt);\n }\n\n // Update reward vairables for all pools. Be careful of gas spending!\n function massUpdatePools() public {\n uint256 length = poolInfo.length;\n for (uint256 pid = 0; pid < length; ++pid) {\n updatePool(pid);\n }\n }\n\n // Update reward variables of the given pool to be up-to-date.\n function updatePool(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n if (block.timestamp <= pool.lastRewardTimestamp) {\n return;\n }\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (lpSupply == 0) {\n pool.lastRewardTimestamp = block.timestamp;\n return;\n }\n uint256 multiplier = getMultiplier(pool.lastRewardTimestamp, block.timestamp);\n uint256 sushiReward = multiplier.mul(sushiPerSec).mul(pool.allocPoint).div(totalAllocPoint);\n sushi.mint(devaddr, sushiReward.div(10));\n sushi.mint(address(this), sushiReward);\n pool.accSushiPerShare = pool.accSushiPerShare.add(sushiReward.mul(1e12).div(lpSupply));\n pool.lastRewardTimestamp = block.timestamp;\n }\n\n // Deposit LP tokens to MasterChef for SUSHI allocation.\n function deposit(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n updatePool(_pid);\n if (user.amount > 0) {\n uint256 pending = user.amount.mul(pool.accSushiPerShare).div(1e12).sub(user.rewardDebt);\n safeSushiTransfer(msg.sender, pending);\n }\n pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);\n user.amount = user.amount.add(_amount);\n user.rewardDebt = user.amount.mul(pool.accSushiPerShare).div(1e12);\n emit Deposit(msg.sender, _pid, _amount);\n }\n\n // Withdraw LP tokens from MasterChef.\n function withdraw(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n require(user.amount >= _amount, \"withdraw: not good\");\n updatePool(_pid);\n uint256 pending = user.amount.mul(pool.accSushiPerShare).div(1e12).sub(user.rewardDebt);\n safeSushiTransfer(msg.sender, pending);\n user.amount = user.amount.sub(_amount);\n user.rewardDebt = user.amount.mul(pool.accSushiPerShare).div(1e12);\n pool.lpToken.safeTransfer(address(msg.sender), _amount);\n emit Withdraw(msg.sender, _pid, _amount);\n }\n\n // Withdraw without caring about rewards. EMERGENCY ONLY.\n function emergencyWithdraw(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n pool.lpToken.safeTransfer(address(msg.sender), user.amount);\n emit EmergencyWithdraw(msg.sender, _pid, user.amount);\n user.amount = 0;\n user.rewardDebt = 0;\n }\n\n // Safe sushi transfer function, just in case if rounding error causes pool to not have enough SUSHIs.\n function safeSushiTransfer(address _to, uint256 _amount) internal {\n uint256 sushiBal = sushi.balanceOf(address(this));\n if (_amount > sushiBal) {\n sushi.transfer(_to, sushiBal);\n } else {\n sushi.transfer(_to, _amount);\n }\n }\n\n // Update dev address by the previous dev.\n function dev(address _devaddr) public {\n require(msg.sender == devaddr, \"dev: wut?\");\n devaddr = _devaddr;\n }\n}\n" + }, + "contracts/sushi/SushiToken.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\n// SushiToken with Governance.\ncontract SushiToken is ERC20(\"SushiToken\", \"SUSHI\"), Ownable {\n /// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef).\n function mint(address _to, uint256 _amount) public onlyOwner {\n _mint(_to, _amount);\n _moveDelegates(address(0), _delegates[_to], _amount);\n }\n\n // Copied and modified from YAM code:\n // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol\n // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol\n // Which is copied and modified from COMPOUND:\n // https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol\n\n /// @notice A record of each accounts delegate\n mapping(address => address) internal _delegates;\n\n /// @notice A checkpoint for marking number of votes from a given block\n struct Checkpoint {\n uint32 fromBlock;\n uint256 votes;\n }\n\n /// @notice A record of votes checkpoints for each account, by index\n mapping(address => mapping(uint32 => Checkpoint)) public checkpoints;\n\n /// @notice The number of checkpoints for each account\n mapping(address => uint32) public numCheckpoints;\n\n /// @notice The EIP-712 typehash for the contract's domain\n bytes32 public constant DOMAIN_TYPEHASH =\n keccak256(\"EIP712Domain(string name,uint256 chainId,address verifyingContract)\");\n\n /// @notice The EIP-712 typehash for the delegation struct used by the contract\n bytes32 public constant DELEGATION_TYPEHASH =\n keccak256(\"Delegation(address delegatee,uint256 nonce,uint256 expiry)\");\n\n /// @notice A record of states for signing / validating signatures\n mapping(address => uint256) public nonces;\n\n /// @notice An event thats emitted when an account changes its delegate\n event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);\n\n /// @notice An event thats emitted when a delegate account's vote balance changes\n event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);\n\n /**\n * @notice Delegate votes from `msg.sender` to `delegatee`\n * @param delegator The address to get delegatee for\n */\n function delegates(address delegator) external view returns (address) {\n return _delegates[delegator];\n }\n\n /**\n * @notice Delegate votes from `msg.sender` to `delegatee`\n * @param delegatee The address to delegate votes to\n */\n function delegate(address delegatee) external {\n return _delegate(msg.sender, delegatee);\n }\n\n /**\n * @notice Delegates votes from signatory to `delegatee`\n * @param delegatee The address to delegate votes to\n * @param nonce The contract state required to match the signature\n * @param expiry The time at which to expire the signature\n * @param v The recovery byte of the signature\n * @param r Half of the ECDSA signature pair\n * @param s Half of the ECDSA signature pair\n */\n function delegateBySig(\n address delegatee,\n uint256 nonce,\n uint256 expiry,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external {\n bytes32 domainSeparator = keccak256(\n abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name())), getChainId(), address(this))\n );\n\n bytes32 structHash = keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry));\n\n bytes32 digest = keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\n\n address signatory = ecrecover(digest, v, r, s);\n require(signatory != address(0), \"SUSHI::delegateBySig: invalid signature\");\n require(nonce == nonces[signatory]++, \"SUSHI::delegateBySig: invalid nonce\");\n require(now <= expiry, \"SUSHI::delegateBySig: signature expired\");\n return _delegate(signatory, delegatee);\n }\n\n /**\n * @notice Gets the current votes balance for `account`\n * @param account The address to get votes balance\n * @return The number of current votes for `account`\n */\n function getCurrentVotes(address account) external view returns (uint256) {\n uint32 nCheckpoints = numCheckpoints[account];\n return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;\n }\n\n /**\n * @notice Determine the prior number of votes for an account as of a block number\n * @dev Block number must be a finalized block or else this function will revert to prevent misinformation.\n * @param account The address of the account to check\n * @param blockNumber The block number to get the vote balance at\n * @return The number of votes the account had as of the given block\n */\n function getPriorVotes(address account, uint256 blockNumber) external view returns (uint256) {\n require(blockNumber < block.number, \"SUSHI::getPriorVotes: not yet determined\");\n\n uint32 nCheckpoints = numCheckpoints[account];\n if (nCheckpoints == 0) {\n return 0;\n }\n\n // First check most recent balance\n if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {\n return checkpoints[account][nCheckpoints - 1].votes;\n }\n\n // Next check implicit zero balance\n if (checkpoints[account][0].fromBlock > blockNumber) {\n return 0;\n }\n\n uint32 lower = 0;\n uint32 upper = nCheckpoints - 1;\n while (upper > lower) {\n uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow\n Checkpoint memory cp = checkpoints[account][center];\n if (cp.fromBlock == blockNumber) {\n return cp.votes;\n } else if (cp.fromBlock < blockNumber) {\n lower = center;\n } else {\n upper = center - 1;\n }\n }\n return checkpoints[account][lower].votes;\n }\n\n function _delegate(address delegator, address delegatee) internal {\n address currentDelegate = _delegates[delegator];\n uint256 delegatorBalance = balanceOf(delegator); // balance of underlying SUSHIs (not scaled);\n _delegates[delegator] = delegatee;\n\n emit DelegateChanged(delegator, currentDelegate, delegatee);\n\n _moveDelegates(currentDelegate, delegatee, delegatorBalance);\n }\n\n function _moveDelegates(\n address srcRep,\n address dstRep,\n uint256 amount\n ) internal {\n if (srcRep != dstRep && amount > 0) {\n if (srcRep != address(0)) {\n // decrease old representative\n uint32 srcRepNum = numCheckpoints[srcRep];\n uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;\n uint256 srcRepNew = srcRepOld.sub(amount);\n _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);\n }\n\n if (dstRep != address(0)) {\n // increase new representative\n uint32 dstRepNum = numCheckpoints[dstRep];\n uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;\n uint256 dstRepNew = dstRepOld.add(amount);\n _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);\n }\n }\n }\n\n function _writeCheckpoint(\n address delegatee,\n uint32 nCheckpoints,\n uint256 oldVotes,\n uint256 newVotes\n ) internal {\n uint32 blockNumber = safe32(block.number, \"SUSHI::_writeCheckpoint: block number exceeds 32 bits\");\n\n if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {\n checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;\n } else {\n checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);\n numCheckpoints[delegatee] = nCheckpoints + 1;\n }\n\n emit DelegateVotesChanged(delegatee, oldVotes, newVotes);\n }\n\n function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) {\n require(n < 2**32, errorMessage);\n return uint32(n);\n }\n\n function getChainId() internal pure returns (uint256) {\n uint256 chainId;\n assembly {\n chainId := chainid()\n }\n return chainId;\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../../utils/Context.sol\";\nimport \"./IERC20.sol\";\nimport \"../../math/SafeMath.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin guidelines: functions revert instead\n * of returning `false` on failure. This behavior is nonetheless conventional\n * and does not conflict with the expectations of ERC20 applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20 {\n using SafeMath for uint256;\n\n mapping (address => uint256) private _balances;\n\n mapping (address => mapping (address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n uint8 private _decimals;\n\n /**\n * @dev Sets the values for {name} and {symbol}, initializes {decimals} with\n * a default value of 18.\n *\n * To select a different value for {decimals}, use {_setupDecimals}.\n *\n * All three of these values are immutable: they can only be set once during\n * construction.\n */\n constructor (string memory name_, string memory symbol_) public {\n _name = name_;\n _symbol = symbol_;\n _decimals = 18;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5,05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is\n * called.\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual returns (uint8) {\n return _decimals;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `recipient` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address recipient, uint256 amount) public virtual override returns (bool) {\n _transfer(_msgSender(), recipient, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n _approve(_msgSender(), spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * Requirements:\n *\n * - `sender` and `recipient` cannot be the zero address.\n * - `sender` must have a balance of at least `amount`.\n * - the caller must have allowance for ``sender``'s tokens of at least\n * `amount`.\n */\n function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {\n _transfer(sender, recipient, amount);\n _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, \"ERC20: transfer amount exceeds allowance\"));\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, \"ERC20: decreased allowance below zero\"));\n return true;\n }\n\n /**\n * @dev Moves tokens `amount` from `sender` to `recipient`.\n *\n * This is internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `sender` cannot be the zero address.\n * - `recipient` cannot be the zero address.\n * - `sender` must have a balance of at least `amount`.\n */\n function _transfer(address sender, address recipient, uint256 amount) internal virtual {\n require(sender != address(0), \"ERC20: transfer from the zero address\");\n require(recipient != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(sender, recipient, amount);\n\n _balances[sender] = _balances[sender].sub(amount, \"ERC20: transfer amount exceeds balance\");\n _balances[recipient] = _balances[recipient].add(amount);\n emit Transfer(sender, recipient, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply = _totalSupply.add(amount);\n _balances[account] = _balances[account].add(amount);\n emit Transfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n _balances[account] = _balances[account].sub(amount, \"ERC20: burn amount exceeds balance\");\n _totalSupply = _totalSupply.sub(amount);\n emit Transfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(address owner, address spender, uint256 amount) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Sets {decimals} to a value other than the default one of 18.\n *\n * WARNING: This function should only be called from the constructor. Most\n * applications that interact with token contracts will not expect\n * {decimals} to ever change, and may work incorrectly if it does.\n */\n function _setupDecimals(uint8 decimals_) internal virtual {\n _decimals = decimals_;\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be to transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }\n}\n" + }, + "contracts/mocks/ERC20MockDecimals.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\n/// @title ERC20MockDecimals\n/// @author Trader Joe\n/// @dev ONLY FOR TESTS\ncontract ERC20MockDecimals is ERC20, Ownable {\n uint8 private decimalsOverride;\n\n /// @dev Constructor\n /// @param _decimals The number of decimals for this token\n constructor(uint8 _decimals) public ERC20(\"ERC20Mock\", \"ERC20M\") {\n decimalsOverride = _decimals;\n }\n\n /// @dev Define the number of decimals\n /// @return The number of decimals\n function decimals() public view override returns (uint8) {\n return decimalsOverride;\n }\n\n /// @dev Mint _amount to _to. Callable only by owner\n /// @param _to The address that will receive the mint\n /// @param _amount The amount to be minted\n function mint(address _to, uint256 _amount) external {\n _mint(_to, _amount);\n }\n}\n" + }, + "contracts/mocks/ERC20Mock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract ERC20Mock is ERC20, Ownable {\n constructor(\n string memory name,\n string memory symbol,\n uint256 supply\n ) public ERC20(name, symbol) {\n _mint(msg.sender, supply);\n }\n}\n" + }, + "contracts/JoeToken.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\n// JoeToken with Governance.\ncontract JoeToken is ERC20(\"JoeToken\", \"JOE\"), Ownable {\n /// @notice Total number of tokens\n uint256 public maxSupply = 500_000_000e18; // 500 million Joe\n\n /// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterJoe).\n function mint(address _to, uint256 _amount) public onlyOwner {\n require(totalSupply().add(_amount) <= maxSupply, \"JOE::mint: cannot exceed max supply\");\n _mint(_to, _amount);\n _moveDelegates(address(0), _delegates[_to], _amount);\n }\n\n // Copied and modified from YAM code:\n // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol\n // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol\n // Which is copied and modified from COMPOUND:\n // https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol\n\n /// @notice A record of each accounts delegate\n mapping(address => address) internal _delegates;\n\n /// @notice A checkpoint for marking number of votes from a given block\n struct Checkpoint {\n uint32 fromBlock;\n uint256 votes;\n }\n\n /// @notice A record of votes checkpoints for each account, by index\n mapping(address => mapping(uint32 => Checkpoint)) public checkpoints;\n\n /// @notice The number of checkpoints for each account\n mapping(address => uint32) public numCheckpoints;\n\n /// @notice The EIP-712 typehash for the contract's domain\n bytes32 public constant DOMAIN_TYPEHASH =\n keccak256(\"EIP712Domain(string name,uint256 chainId,address verifyingContract)\");\n\n /// @notice The EIP-712 typehash for the delegation struct used by the contract\n bytes32 public constant DELEGATION_TYPEHASH =\n keccak256(\"Delegation(address delegatee,uint256 nonce,uint256 expiry)\");\n\n /// @notice A record of states for signing / validating signatures\n mapping(address => uint256) public nonces;\n\n /// @notice An event thats emitted when an account changes its delegate\n event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);\n\n /// @notice An event thats emitted when a delegate account's vote balance changes\n event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);\n\n /**\n * @notice Delegate votes from `msg.sender` to `delegatee`\n * @param delegator The address to get delegatee for\n */\n function delegates(address delegator) external view returns (address) {\n return _delegates[delegator];\n }\n\n /**\n * @notice Delegate votes from `msg.sender` to `delegatee`\n * @param delegatee The address to delegate votes to\n */\n function delegate(address delegatee) external {\n return _delegate(msg.sender, delegatee);\n }\n\n /**\n * @notice Delegates votes from signatory to `delegatee`\n * @param delegatee The address to delegate votes to\n * @param nonce The contract state required to match the signature\n * @param expiry The time at which to expire the signature\n * @param v The recovery byte of the signature\n * @param r Half of the ECDSA signature pair\n * @param s Half of the ECDSA signature pair\n */\n function delegateBySig(\n address delegatee,\n uint256 nonce,\n uint256 expiry,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external {\n bytes32 domainSeparator = keccak256(\n abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name())), getChainId(), address(this))\n );\n\n bytes32 structHash = keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry));\n\n bytes32 digest = keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\n\n address signatory = ecrecover(digest, v, r, s);\n require(signatory != address(0), \"JOE::delegateBySig: invalid signature\");\n require(nonce == nonces[signatory]++, \"JOE::delegateBySig: invalid nonce\");\n require(now <= expiry, \"JOE::delegateBySig: signature expired\");\n return _delegate(signatory, delegatee);\n }\n\n /**\n * @notice Gets the current votes balance for `account`\n * @param account The address to get votes balance\n * @return The number of current votes for `account`\n */\n function getCurrentVotes(address account) external view returns (uint256) {\n uint32 nCheckpoints = numCheckpoints[account];\n return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;\n }\n\n /**\n * @notice Determine the prior number of votes for an account as of a block number\n * @dev Block number must be a finalized block or else this function will revert to prevent misinformation.\n * @param account The address of the account to check\n * @param blockNumber The block number to get the vote balance at\n * @return The number of votes the account had as of the given block\n */\n function getPriorVotes(address account, uint256 blockNumber) external view returns (uint256) {\n require(blockNumber < block.number, \"JOE::getPriorVotes: not yet determined\");\n\n uint32 nCheckpoints = numCheckpoints[account];\n if (nCheckpoints == 0) {\n return 0;\n }\n\n // First check most recent balance\n if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {\n return checkpoints[account][nCheckpoints - 1].votes;\n }\n\n // Next check implicit zero balance\n if (checkpoints[account][0].fromBlock > blockNumber) {\n return 0;\n }\n\n uint32 lower = 0;\n uint32 upper = nCheckpoints - 1;\n while (upper > lower) {\n uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow\n Checkpoint memory cp = checkpoints[account][center];\n if (cp.fromBlock == blockNumber) {\n return cp.votes;\n } else if (cp.fromBlock < blockNumber) {\n lower = center;\n } else {\n upper = center - 1;\n }\n }\n return checkpoints[account][lower].votes;\n }\n\n function _delegate(address delegator, address delegatee) internal {\n address currentDelegate = _delegates[delegator];\n uint256 delegatorBalance = balanceOf(delegator); // balance of underlying JOEs (not scaled);\n _delegates[delegator] = delegatee;\n\n emit DelegateChanged(delegator, currentDelegate, delegatee);\n\n _moveDelegates(currentDelegate, delegatee, delegatorBalance);\n }\n\n function _moveDelegates(\n address srcRep,\n address dstRep,\n uint256 amount\n ) internal {\n if (srcRep != dstRep && amount > 0) {\n if (srcRep != address(0)) {\n // decrease old representative\n uint32 srcRepNum = numCheckpoints[srcRep];\n uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;\n uint256 srcRepNew = srcRepOld.sub(amount);\n _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);\n }\n\n if (dstRep != address(0)) {\n // increase new representative\n uint32 dstRepNum = numCheckpoints[dstRep];\n uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;\n uint256 dstRepNew = dstRepOld.add(amount);\n _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);\n }\n }\n }\n\n function _writeCheckpoint(\n address delegatee,\n uint32 nCheckpoints,\n uint256 oldVotes,\n uint256 newVotes\n ) internal {\n uint32 blockNumber = safe32(block.number, \"JOE::_writeCheckpoint: block number exceeds 32 bits\");\n\n if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {\n checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;\n } else {\n checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);\n numCheckpoints[delegatee] = nCheckpoints + 1;\n }\n\n emit DelegateVotesChanged(delegatee, oldVotes, newVotes);\n }\n\n function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) {\n require(n < 2**32, errorMessage);\n return uint32(n);\n }\n\n function getChainId() internal pure returns (uint256) {\n uint256 chainId;\n assembly {\n chainId := chainid()\n }\n return chainId;\n }\n}\n" + }, + "contracts/MasterChefJoeV2.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/utils/EnumerableSet.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./JoeToken.sol\";\nimport \"./libraries/BoringERC20.sol\";\n\n\ninterface IRewarder {\n using SafeERC20 for IERC20;\n\n function onJoeReward(address user, uint256 newLpAmount) external;\n\n function pendingTokens(address user) external view returns (uint256 pending);\n\n function rewardToken() external view returns (address);\n}\n\n// MasterChefJoe is a boss. He says \"go f your blocks lego boy, I'm gonna use timestamp instead\".\n// And to top it off, it takes no risks. Because the biggest risk is operator error.\n// So we make it virtually impossible for the operator of this contract to cause a bug with people's harvests.\n//\n// Note that it's ownable and the owner wields tremendous power. The ownership\n// will be transferred to a governance smart contract once JOE is sufficiently\n// distributed and the community can show to govern itself.\n//\n// With thanks to the Lydia Finance team.\n//\n// Godspeed and may the 10x be with you.\ncontract MasterChefJoeV2 is Ownable {\n using SafeMath for uint256;\n using BoringERC20 for IERC20;\n using EnumerableSet for EnumerableSet.AddressSet;\n\n // Info of each user.\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n //\n // We do some fancy math here. Basically, any point in time, the amount of JOEs\n // entitled to a user but is pending to be distributed is:\n //\n // pending reward = (user.amount * pool.accJoePerShare) - user.rewardDebt\n //\n // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:\n // 1. The pool's `accJoePerShare` (and `lastRewardTimestamp`) gets updated.\n // 2. User receives the pending reward sent to his/her address.\n // 3. User's `amount` gets updated.\n // 4. User's `rewardDebt` gets updated.\n }\n\n // Info of each pool.\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOEs to distribute per second.\n uint256 lastRewardTimestamp; // Last timestamp that JOEs distribution occurs.\n uint256 accJoePerShare; // Accumulated JOEs per share, times 1e12. See below.\n IRewarder rewarder;\n }\n\n // The JOE TOKEN!\n JoeToken public joe;\n // Dev address.\n address public devAddr;\n // Treasury address.\n address public treasuryAddr;\n // Investor address\n address public investorAddr;\n // JOE tokens created per second.\n uint256 public joePerSec;\n // Percentage of pool rewards that goto the devs.\n uint256 public devPercent;\n // Percentage of pool rewards that goes to the treasury.\n uint256 public treasuryPercent;\n // Percentage of pool rewards that goes to the investor.\n uint256 public investorPercent;\n\n // Info of each pool.\n PoolInfo[] public poolInfo;\n // Set of all LP tokens that have been added as pools\n EnumerableSet.AddressSet private lpTokens;\n // Info of each user that stakes LP tokens.\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n // Total allocation points. Must be the sum of all allocation points in all pools.\n uint256 public totalAllocPoint;\n // The timestamp when JOE mining starts.\n uint256 public startTimestamp;\n\n event Add(uint256 indexed pid, uint256 allocPoint, IERC20 indexed lpToken, IRewarder indexed rewarder);\n event Set(uint256 indexed pid, uint256 allocPoint, IRewarder indexed rewarder, bool overwrite);\n event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\n event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event UpdatePool(uint256 indexed pid, uint256 lastRewardTimestamp, uint256 lpSupply, uint256 accJoePerShare);\n event Harvest(address indexed user, uint256 indexed pid, uint256 amount);\n event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event SetDevAddress(address indexed oldAddress, address indexed newAddress);\n event UpdateEmissionRate(address indexed user, uint256 _joePerSec);\n\n constructor(\n JoeToken _joe,\n address _devAddr,\n address _treasuryAddr,\n address _investorAddr,\n uint256 _joePerSec,\n uint256 _startTimestamp,\n uint256 _devPercent,\n uint256 _treasuryPercent,\n uint256 _investorPercent\n ) public {\n require(0 <= _devPercent && _devPercent <= 1000, \"constructor: invalid dev percent value\");\n require(0 <= _treasuryPercent && _treasuryPercent <= 1000, \"constructor: invalid treasury percent value\");\n require(0 <= _investorPercent && _investorPercent <= 1000, \"constructor: invalid investor percent value\");\n require(_devPercent + _treasuryPercent + _investorPercent <= 1000, \"constructor: total percent over max\");\n joe = _joe;\n devAddr = _devAddr;\n treasuryAddr = _treasuryAddr;\n investorAddr = _investorAddr;\n joePerSec = _joePerSec;\n startTimestamp = _startTimestamp;\n devPercent = _devPercent;\n treasuryPercent = _treasuryPercent;\n investorPercent = _investorPercent;\n totalAllocPoint = 0;\n }\n\n function poolLength() external view returns (uint256) {\n return poolInfo.length;\n }\n\n // Add a new lp to the pool. Can only be called by the owner.\n // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.\n function add(\n uint256 _allocPoint,\n IERC20 _lpToken,\n IRewarder _rewarder\n ) public onlyOwner {\n require(Address.isContract(address(_lpToken)), \"add: LP token must be a valid contract\");\n require(\n Address.isContract(address(_rewarder)) || address(_rewarder) == address(0),\n \"add: rewarder must be contract or zero\"\n );\n require(!lpTokens.contains(address(_lpToken)), \"add: LP already added\");\n massUpdatePools();\n uint256 lastRewardTimestamp = block.timestamp > startTimestamp ? block.timestamp : startTimestamp;\n totalAllocPoint = totalAllocPoint.add(_allocPoint);\n poolInfo.push(\n PoolInfo({\n lpToken: _lpToken,\n allocPoint: _allocPoint,\n lastRewardTimestamp: lastRewardTimestamp,\n accJoePerShare: 0,\n rewarder: _rewarder\n })\n );\n lpTokens.add(address(_lpToken));\n emit Add(poolInfo.length.sub(1), _allocPoint, _lpToken, _rewarder);\n }\n\n // Update the given pool's JOE allocation point. Can only be called by the owner.\n function set(\n uint256 _pid,\n uint256 _allocPoint,\n IRewarder _rewarder,\n bool overwrite\n ) public onlyOwner {\n require(\n Address.isContract(address(_rewarder)) || address(_rewarder) == address(0),\n \"set: rewarder must be contract or zero\"\n );\n massUpdatePools();\n totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);\n poolInfo[_pid].allocPoint = _allocPoint;\n if (overwrite) {\n poolInfo[_pid].rewarder = _rewarder;\n }\n emit Set(_pid, _allocPoint, overwrite ? _rewarder : poolInfo[_pid].rewarder, overwrite);\n }\n\n // View function to see pending JOEs on frontend.\n function pendingTokens(uint256 _pid, address _user)\n external\n view\n returns (\n uint256 pendingJoe,\n address bonusTokenAddress,\n string memory bonusTokenSymbol,\n uint256 pendingBonusToken\n )\n {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_user];\n uint256 accJoePerShare = pool.accJoePerShare;\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (block.timestamp > pool.lastRewardTimestamp && lpSupply != 0) {\n uint256 multiplier = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 lpPercent = 1000 - devPercent - treasuryPercent - investorPercent;\n uint256 joeReward = multiplier.mul(joePerSec).mul(pool.allocPoint).div(totalAllocPoint).mul(lpPercent).div(\n 1000\n );\n accJoePerShare = accJoePerShare.add(joeReward.mul(1e12).div(lpSupply));\n }\n pendingJoe = user.amount.mul(accJoePerShare).div(1e12).sub(user.rewardDebt);\n\n // If it's a double reward farm, we return info about the bonus token\n if (address(pool.rewarder) != address(0)) {\n (bonusTokenAddress, bonusTokenSymbol) = rewarderBonusTokenInfo(_pid);\n pendingBonusToken = pool.rewarder.pendingTokens(_user);\n }\n }\n\n // Get bonus token info from the rewarder contract for a given pool, if it is a double reward farm\n function rewarderBonusTokenInfo(uint256 _pid)\n public\n view\n returns (address bonusTokenAddress, string memory bonusTokenSymbol)\n {\n PoolInfo storage pool = poolInfo[_pid];\n if (address(pool.rewarder) != address(0)) {\n bonusTokenAddress = address(pool.rewarder.rewardToken());\n bonusTokenSymbol = IERC20(pool.rewarder.rewardToken()).safeSymbol();\n }\n }\n\n // Update reward variables for all pools. Be careful of gas spending!\n function massUpdatePools() public {\n uint256 length = poolInfo.length;\n for (uint256 pid = 0; pid < length; ++pid) {\n updatePool(pid);\n }\n }\n\n // Update reward variables of the given pool to be up-to-date.\n function updatePool(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n if (block.timestamp <= pool.lastRewardTimestamp) {\n return;\n }\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (lpSupply == 0) {\n pool.lastRewardTimestamp = block.timestamp;\n return;\n }\n uint256 multiplier = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 joeReward = multiplier.mul(joePerSec).mul(pool.allocPoint).div(totalAllocPoint);\n uint256 lpPercent = 1000 - devPercent - treasuryPercent - investorPercent;\n joe.mint(devAddr, joeReward.mul(devPercent).div(1000));\n joe.mint(treasuryAddr, joeReward.mul(treasuryPercent).div(1000));\n joe.mint(investorAddr, joeReward.mul(investorPercent).div(1000));\n joe.mint(address(this), joeReward.mul(lpPercent).div(1000));\n pool.accJoePerShare = pool.accJoePerShare.add(joeReward.mul(1e12).div(lpSupply).mul(lpPercent).div(1000));\n pool.lastRewardTimestamp = block.timestamp;\n emit UpdatePool(_pid, pool.lastRewardTimestamp, lpSupply, pool.accJoePerShare);\n }\n\n // Deposit LP tokens to MasterChef for JOE allocation.\n function deposit(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n updatePool(_pid);\n if (user.amount > 0) {\n // Harvest JOE\n uint256 pending = user.amount.mul(pool.accJoePerShare).div(1e12).sub(user.rewardDebt);\n safeJoeTransfer(msg.sender, pending);\n emit Harvest(msg.sender, _pid, pending);\n }\n user.amount = user.amount.add(_amount);\n user.rewardDebt = user.amount.mul(pool.accJoePerShare).div(1e12);\n\n IRewarder rewarder = poolInfo[_pid].rewarder;\n if (address(rewarder) != address(0)) {\n rewarder.onJoeReward(msg.sender, user.amount);\n }\n\n pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);\n emit Deposit(msg.sender, _pid, _amount);\n }\n\n // Withdraw LP tokens from MasterChef.\n function withdraw(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n require(user.amount >= _amount, \"withdraw: not good\");\n\n updatePool(_pid);\n\n // Harvest JOE\n uint256 pending = user.amount.mul(pool.accJoePerShare).div(1e12).sub(user.rewardDebt);\n safeJoeTransfer(msg.sender, pending);\n emit Harvest(msg.sender, _pid, pending);\n\n user.amount = user.amount.sub(_amount);\n user.rewardDebt = user.amount.mul(pool.accJoePerShare).div(1e12);\n\n IRewarder rewarder = poolInfo[_pid].rewarder;\n if (address(rewarder) != address(0)) {\n rewarder.onJoeReward(msg.sender, user.amount);\n }\n\n pool.lpToken.safeTransfer(address(msg.sender), _amount);\n emit Withdraw(msg.sender, _pid, _amount);\n }\n\n // Withdraw without caring about rewards. EMERGENCY ONLY.\n function emergencyWithdraw(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n pool.lpToken.safeTransfer(address(msg.sender), user.amount);\n emit EmergencyWithdraw(msg.sender, _pid, user.amount);\n user.amount = 0;\n user.rewardDebt = 0;\n }\n\n // Safe joe transfer function, just in case if rounding error causes pool to not have enough JOEs.\n function safeJoeTransfer(address _to, uint256 _amount) internal {\n uint256 joeBal = joe.balanceOf(address(this));\n if (_amount > joeBal) {\n joe.transfer(_to, joeBal);\n } else {\n joe.transfer(_to, _amount);\n }\n }\n\n // Update dev address by the previous dev.\n function dev(address _devAddr) public {\n require(msg.sender == devAddr, \"dev: wut?\");\n devAddr = _devAddr;\n emit SetDevAddress(msg.sender, _devAddr);\n }\n\n function setDevPercent(uint256 _newDevPercent) public onlyOwner {\n require(0 <= _newDevPercent && _newDevPercent <= 1000, \"setDevPercent: invalid percent value\");\n require(treasuryPercent + _newDevPercent + investorPercent <= 1000, \"setDevPercent: total percent over max\");\n devPercent = _newDevPercent;\n }\n\n // Update treasury address by the previous treasury.\n function setTreasuryAddr(address _treasuryAddr) public {\n require(msg.sender == treasuryAddr, \"setTreasuryAddr: wut?\");\n treasuryAddr = _treasuryAddr;\n }\n\n function setTreasuryPercent(uint256 _newTreasuryPercent) public onlyOwner {\n require(0 <= _newTreasuryPercent && _newTreasuryPercent <= 1000, \"setTreasuryPercent: invalid percent value\");\n require(\n devPercent + _newTreasuryPercent + investorPercent <= 1000,\n \"setTreasuryPercent: total percent over max\"\n );\n treasuryPercent = _newTreasuryPercent;\n }\n\n // Update the investor address by the previous investor.\n function setInvestorAddr(address _investorAddr) public {\n require(msg.sender == investorAddr, \"setInvestorAddr: wut?\");\n investorAddr = _investorAddr;\n }\n\n function setInvestorPercent(uint256 _newInvestorPercent) public onlyOwner {\n require(0 <= _newInvestorPercent && _newInvestorPercent <= 1000, \"setInvestorPercent: invalid percent value\");\n require(\n devPercent + _newInvestorPercent + treasuryPercent <= 1000,\n \"setInvestorPercent: total percent over max\"\n );\n investorPercent = _newInvestorPercent;\n }\n\n // Pancake has to add hidden dummy pools inorder to alter the emission,\n // here we make it simple and transparent to all.\n function updateEmissionRate(uint256 _joePerSec) public onlyOwner {\n massUpdatePools();\n joePerSec = _joePerSec;\n emit UpdateEmissionRate(msg.sender, _joePerSec);\n }\n}\n" + }, + "contracts/libraries/BoringERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\n// solhint-disable avoid-low-level-calls\n\nlibrary BoringERC20 {\n bytes4 private constant SIG_SYMBOL = 0x95d89b41; // symbol()\n bytes4 private constant SIG_NAME = 0x06fdde03; // name()\n bytes4 private constant SIG_DECIMALS = 0x313ce567; // decimals()\n bytes4 private constant SIG_TRANSFER = 0xa9059cbb; // transfer(address,uint256)\n bytes4 private constant SIG_TRANSFER_FROM = 0x23b872dd; // transferFrom(address,address,uint256)\n\n function returnDataToString(bytes memory data) internal pure returns (string memory) {\n if (data.length >= 64) {\n return abi.decode(data, (string));\n } else if (data.length == 32) {\n uint8 i = 0;\n while (i < 32 && data[i] != 0) {\n i++;\n }\n bytes memory bytesArray = new bytes(i);\n for (i = 0; i < 32 && data[i] != 0; i++) {\n bytesArray[i] = data[i];\n }\n return string(bytesArray);\n } else {\n return \"???\";\n }\n }\n\n /// @notice Provides a safe ERC20.symbol version which returns '???' as fallback string.\n /// @param token The address of the ERC-20 token contract.\n /// @return (string) Token symbol.\n function safeSymbol(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_SYMBOL));\n return success ? returnDataToString(data) : \"???\";\n }\n\n /// @notice Provides a safe ERC20.name version which returns '???' as fallback string.\n /// @param token The address of the ERC-20 token contract.\n /// @return (string) Token name.\n function safeName(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_NAME));\n return success ? returnDataToString(data) : \"???\";\n }\n\n /// @notice Provides a safe ERC20.decimals version which returns '18' as fallback value.\n /// @param token The address of the ERC-20 token contract.\n /// @return (uint8) Token decimals.\n function safeDecimals(IERC20 token) internal view returns (uint8) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_DECIMALS));\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\n }\n\n /// @notice Provides a safe ERC20.transfer version for different ERC-20 implementations.\n /// Reverts on a failed transfer.\n /// @param token The address of the ERC-20 token.\n /// @param to Transfer tokens to.\n /// @param amount The token amount.\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(SIG_TRANSFER, to, amount));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"BoringERC20: Transfer failed\");\n }\n\n /// @notice Provides a safe ERC20.transferFrom version for different ERC-20 implementations.\n /// Reverts on a failed transfer.\n /// @param token The address of the ERC-20 token.\n /// @param from Transfer tokens from.\n /// @param to Transfer tokens to.\n /// @param amount The token amount.\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(\n abi.encodeWithSelector(SIG_TRANSFER_FROM, from, to, amount)\n );\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"BoringERC20: TransferFrom failed\");\n }\n}\n" + }, + "contracts/sushi/MasterChef.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/utils/EnumerableSet.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./SushiToken.sol\";\n\n// MasterChef is the master of Sushi. He can make Sushi and he is a fair guy.\n//\n// Note that it's ownable and the owner wields tremendous power. The ownership\n// will be transferred to a governance smart contract once SUSHI is sufficiently\n// distributed and the community can show to govern itself.\n//\n// Have fun reading it. Hopefully it's bug-free. God bless.\ncontract MasterChef is Ownable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n // Info of each user.\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n //\n // We do some fancy math here. Basically, any point in time, the amount of SUSHIs\n // entitled to a user but is pending to be distributed is:\n //\n // pending reward = (user.amount * pool.accSushiPerShare) - user.rewardDebt\n //\n // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:\n // 1. The pool's `accSushiPerShare` (and `lastRewardBlock`) gets updated.\n // 2. User receives the pending reward sent to his/her address.\n // 3. User's `amount` gets updated.\n // 4. User's `rewardDebt` gets updated.\n }\n // Info of each pool.\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. SUSHIs to distribute per block.\n uint256 lastRewardBlock; // Last block number that SUSHIs distribution occurs.\n uint256 accSushiPerShare; // Accumulated SUSHIs per share, times 1e12. See below.\n }\n // The SUSHI TOKEN!\n SushiToken public sushi;\n // Dev address.\n address public devaddr;\n // Block number when bonus SUSHI period ends.\n uint256 public bonusEndBlock;\n // SUSHI tokens created per block.\n uint256 public sushiPerBlock;\n // Bonus muliplier for early sushi makers.\n uint256 public constant BONUS_MULTIPLIER = 1;\n // Info of each pool.\n PoolInfo[] public poolInfo;\n // Info of each user that stakes LP tokens.\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n // Total allocation poitns. Must be the sum of all allocation points in all pools.\n uint256 public totalAllocPoint = 0;\n // The block number when SUSHI mining starts.\n uint256 public startBlock;\n event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\n event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\n\n constructor(\n SushiToken _sushi,\n address _devaddr,\n uint256 _sushiPerBlock,\n uint256 _startBlock,\n uint256 _bonusEndBlock\n ) public {\n sushi = _sushi;\n devaddr = _devaddr;\n sushiPerBlock = _sushiPerBlock;\n bonusEndBlock = _bonusEndBlock;\n startBlock = _startBlock;\n }\n\n function poolLength() external view returns (uint256) {\n return poolInfo.length;\n }\n\n // Add a new lp to the pool. Can only be called by the owner.\n // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.\n function add(\n uint256 _allocPoint,\n IERC20 _lpToken,\n bool _withUpdate\n ) public onlyOwner {\n if (_withUpdate) {\n massUpdatePools();\n }\n uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;\n totalAllocPoint = totalAllocPoint.add(_allocPoint);\n poolInfo.push(\n PoolInfo({\n lpToken: _lpToken,\n allocPoint: _allocPoint,\n lastRewardBlock: lastRewardBlock,\n accSushiPerShare: 0\n })\n );\n }\n\n // Update the given pool's SUSHI allocation point. Can only be called by the owner.\n function set(\n uint256 _pid,\n uint256 _allocPoint,\n bool _withUpdate\n ) public onlyOwner {\n if (_withUpdate) {\n massUpdatePools();\n }\n totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);\n poolInfo[_pid].allocPoint = _allocPoint;\n }\n\n // Return reward multiplier over the given _from to _to block.\n function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) {\n if (_to <= bonusEndBlock) {\n return _to.sub(_from).mul(BONUS_MULTIPLIER);\n } else if (_from >= bonusEndBlock) {\n return _to.sub(_from);\n } else {\n return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(_to.sub(bonusEndBlock));\n }\n }\n\n // View function to see pending SUSHIs on frontend.\n function pendingSushi(uint256 _pid, address _user) external view returns (uint256) {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_user];\n uint256 accSushiPerShare = pool.accSushiPerShare;\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (block.number > pool.lastRewardBlock && lpSupply != 0) {\n uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number);\n uint256 sushiReward = multiplier.mul(sushiPerBlock).mul(pool.allocPoint).div(totalAllocPoint);\n accSushiPerShare = accSushiPerShare.add(sushiReward.mul(1e12).div(lpSupply));\n }\n return user.amount.mul(accSushiPerShare).div(1e12).sub(user.rewardDebt);\n }\n\n // Update reward vairables for all pools. Be careful of gas spending!\n function massUpdatePools() public {\n uint256 length = poolInfo.length;\n for (uint256 pid = 0; pid < length; ++pid) {\n updatePool(pid);\n }\n }\n\n // Update reward variables of the given pool to be up-to-date.\n function updatePool(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n if (block.number <= pool.lastRewardBlock) {\n return;\n }\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (lpSupply == 0) {\n pool.lastRewardBlock = block.number;\n return;\n }\n uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number);\n uint256 sushiReward = multiplier.mul(sushiPerBlock).mul(pool.allocPoint).div(totalAllocPoint);\n sushi.mint(devaddr, sushiReward.div(10));\n sushi.mint(address(this), sushiReward);\n pool.accSushiPerShare = pool.accSushiPerShare.add(sushiReward.mul(1e12).div(lpSupply));\n pool.lastRewardBlock = block.number;\n }\n\n // Deposit LP tokens to MasterChef for SUSHI allocation.\n function deposit(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n updatePool(_pid);\n if (user.amount > 0) {\n uint256 pending = user.amount.mul(pool.accSushiPerShare).div(1e12).sub(user.rewardDebt);\n safeSushiTransfer(msg.sender, pending);\n }\n pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);\n user.amount = user.amount.add(_amount);\n user.rewardDebt = user.amount.mul(pool.accSushiPerShare).div(1e12);\n emit Deposit(msg.sender, _pid, _amount);\n }\n\n // Withdraw LP tokens from MasterChef.\n function withdraw(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n require(user.amount >= _amount, \"withdraw: not good\");\n updatePool(_pid);\n uint256 pending = user.amount.mul(pool.accSushiPerShare).div(1e12).sub(user.rewardDebt);\n safeSushiTransfer(msg.sender, pending);\n user.amount = user.amount.sub(_amount);\n user.rewardDebt = user.amount.mul(pool.accSushiPerShare).div(1e12);\n pool.lpToken.safeTransfer(address(msg.sender), _amount);\n emit Withdraw(msg.sender, _pid, _amount);\n }\n\n // Withdraw without caring about rewards. EMERGENCY ONLY.\n function emergencyWithdraw(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n pool.lpToken.safeTransfer(address(msg.sender), user.amount);\n emit EmergencyWithdraw(msg.sender, _pid, user.amount);\n user.amount = 0;\n user.rewardDebt = 0;\n }\n\n // Safe sushi transfer function, just in case if rounding error causes pool to not have enough SUSHIs.\n function safeSushiTransfer(address _to, uint256 _amount) internal {\n uint256 sushiBal = sushi.balanceOf(address(this));\n if (_amount > sushiBal) {\n sushi.transfer(_to, sushiBal);\n } else {\n sushi.transfer(_to, _amount);\n }\n }\n\n // Update dev address by the previous dev.\n function dev(address _devaddr) public {\n require(msg.sender == devaddr, \"dev: wut?\");\n devaddr = _devaddr;\n }\n}\n" + }, + "contracts/timelock/Timelock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// COPIED FROM https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/GovernorAlpha.sol\n// Copyright 2020 Compound Labs, Inc.\n// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Ctrl+f for XXX to see all the modifications.\n\n// XXX: pragma solidity ^0.5.16;\npragma solidity 0.6.12;\n\n// XXX: import \"./SafeMath.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\n\ncontract Timelock {\n using SafeMath for uint256;\n\n event NewAdmin(address indexed newAdmin);\n event NewPendingAdmin(address indexed newPendingAdmin);\n event NewDelay(uint256 indexed newDelay);\n event CancelTransaction(\n bytes32 indexed txHash,\n address indexed target,\n uint256 value,\n string signature,\n bytes data,\n uint256 eta\n );\n event ExecuteTransaction(\n bytes32 indexed txHash,\n address indexed target,\n uint256 value,\n string signature,\n bytes data,\n uint256 eta\n );\n event QueueTransaction(\n bytes32 indexed txHash,\n address indexed target,\n uint256 value,\n string signature,\n bytes data,\n uint256 eta\n );\n\n uint256 public constant GRACE_PERIOD = 14 days;\n uint256 public constant MINIMUM_DELAY = 12 hours;\n uint256 public constant MAXIMUM_DELAY = 30 days;\n\n address public admin;\n address public pendingAdmin;\n uint256 public delay;\n bool public admin_initialized;\n\n mapping(bytes32 => bool) public queuedTransactions;\n\n constructor(address admin_, uint256 delay_) public {\n require(delay_ >= MINIMUM_DELAY, \"Timelock::constructor: Delay must exceed minimum delay.\");\n require(delay_ <= MAXIMUM_DELAY, \"Timelock::constructor: Delay must not exceed maximum delay.\");\n\n admin = admin_;\n delay = delay_;\n admin_initialized = false;\n }\n\n // XXX: function() external payable { }\n receive() external payable {}\n\n function setDelay(uint256 delay_) public {\n require(msg.sender == address(this), \"Timelock::setDelay: Call must come from Timelock.\");\n require(delay_ >= MINIMUM_DELAY, \"Timelock::setDelay: Delay must exceed minimum delay.\");\n require(delay_ <= MAXIMUM_DELAY, \"Timelock::setDelay: Delay must not exceed maximum delay.\");\n delay = delay_;\n\n emit NewDelay(delay);\n }\n\n function acceptAdmin() public {\n require(msg.sender == pendingAdmin, \"Timelock::acceptAdmin: Call must come from pendingAdmin.\");\n admin = msg.sender;\n pendingAdmin = address(0);\n\n emit NewAdmin(admin);\n }\n\n function setPendingAdmin(address pendingAdmin_) public {\n // allows one time setting of admin for deployment purposes\n if (admin_initialized) {\n require(msg.sender == address(this), \"Timelock::setPendingAdmin: Call must come from Timelock.\");\n } else {\n require(msg.sender == admin, \"Timelock::setPendingAdmin: First call must come from admin.\");\n admin_initialized = true;\n }\n pendingAdmin = pendingAdmin_;\n\n emit NewPendingAdmin(pendingAdmin);\n }\n\n function queueTransaction(\n address target,\n uint256 value,\n string memory signature,\n bytes memory data,\n uint256 eta\n ) public returns (bytes32) {\n require(msg.sender == admin, \"Timelock::queueTransaction: Call must come from admin.\");\n require(\n eta >= getBlockTimestamp().add(delay),\n \"Timelock::queueTransaction: Estimated execution block must satisfy delay.\"\n );\n\n bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));\n queuedTransactions[txHash] = true;\n\n emit QueueTransaction(txHash, target, value, signature, data, eta);\n return txHash;\n }\n\n function cancelTransaction(\n address target,\n uint256 value,\n string memory signature,\n bytes memory data,\n uint256 eta\n ) public {\n require(msg.sender == admin, \"Timelock::cancelTransaction: Call must come from admin.\");\n\n bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));\n queuedTransactions[txHash] = false;\n\n emit CancelTransaction(txHash, target, value, signature, data, eta);\n }\n\n function executeTransaction(\n address target,\n uint256 value,\n string memory signature,\n bytes memory data,\n uint256 eta\n ) public payable returns (bytes memory) {\n require(msg.sender == admin, \"Timelock::executeTransaction: Call must come from admin.\");\n\n bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));\n require(queuedTransactions[txHash], \"Timelock::executeTransaction: Transaction hasn't been queued.\");\n require(getBlockTimestamp() >= eta, \"Timelock::executeTransaction: Transaction hasn't surpassed time lock.\");\n require(getBlockTimestamp() <= eta.add(GRACE_PERIOD), \"Timelock::executeTransaction: Transaction is stale.\");\n\n queuedTransactions[txHash] = false;\n\n bytes memory callData;\n\n if (bytes(signature).length == 0) {\n callData = data;\n } else {\n callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data);\n }\n\n // solium-disable-next-line security/no-call-value\n (bool success, bytes memory returnData) = target.call.value(value)(callData);\n require(success, \"Timelock::executeTransaction: Transaction execution reverted.\");\n\n emit ExecuteTransaction(txHash, target, value, signature, data, eta);\n\n return returnData;\n }\n\n function getBlockTimestamp() internal view returns (uint256) {\n // solium-disable-next-line security/no-block-members\n return block.timestamp;\n }\n}\n" + }, + "contracts/timelock/CustomMasterChefJoeV2Timelock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// COPIED FROM https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/GovernorAlpha.sol\n// Copyright 2020 Compound Labs, Inc.\n// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Ctrl+f for XXX to see all the modifications.\n\n// XXX: pragma solidity ^0.5.16;\npragma solidity 0.6.12;\n\n// XXX: import \"./SafeMath.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\n\ncontract CustomMasterChefJoeV2Timelock {\n using SafeMath for uint256;\n\n event NewAdmin(address indexed newAdmin);\n event NewPendingAdmin(address indexed newPendingAdmin);\n event NewDelay(uint256 indexed newDelay);\n event CancelTransaction(\n bytes32 indexed txHash,\n address indexed target,\n uint256 value,\n string signature,\n bytes data,\n uint256 eta\n );\n event ExecuteTransaction(\n bytes32 indexed txHash,\n address indexed target,\n uint256 value,\n string signature,\n bytes data,\n uint256 eta\n );\n event QueueTransaction(\n bytes32 indexed txHash,\n address indexed target,\n uint256 value,\n string signature,\n bytes data,\n uint256 eta\n );\n\n uint256 public constant GRACE_PERIOD = 14 days;\n uint256 public constant MINIMUM_DELAY = 12 hours;\n uint256 public constant MAXIMUM_DELAY = 30 days;\n\n string private constant SET_DEV_PERCENT_SIG = \"setDevPercent(uint256)\";\n string private constant SET_TREASURY_PERCENT_SIG = \"setTreasuryPercent(uint256)\";\n string private constant SET_INVESTOR_PERCENT_SIG = \"setInvestorPercent(uint256)\";\n string private constant UPDATE_EMISSION_RATE_SIG = \"updateEmissionRate(uint256)\";\n\n address public admin;\n address public pendingAdmin;\n uint256 public delay;\n uint256 public devPercentLimit;\n uint256 public investorPercentLimit;\n uint256 public treasuryPercentLimit;\n uint256 public joePerSecLimit;\n bool public admin_initialized;\n\n mapping(bytes32 => bool) public queuedTransactions;\n\n modifier withinLimits(string memory signature, bytes memory data) {\n if (keccak256(bytes(signature)) == keccak256(bytes(SET_DEV_PERCENT_SIG))) {\n uint256 devPercent = abi.decode(data, (uint256));\n require(\n devPercent <= devPercentLimit,\n \"CustomMasterChefJoeV2Timelock::withinLimits: devPercent must not exceed limit.\"\n );\n } else if (keccak256(bytes(signature)) == keccak256(bytes(SET_TREASURY_PERCENT_SIG))) {\n uint256 treasuryPercent = abi.decode(data, (uint256));\n require(\n treasuryPercent <= treasuryPercentLimit,\n \"CustomMasterChefJoeV2Timelock::withinLimits: treasuryPercent must not exceed limit.\"\n );\n } else if (keccak256(bytes(signature)) == keccak256(bytes(SET_INVESTOR_PERCENT_SIG))) {\n uint256 investorPercent = abi.decode(data, (uint256));\n require(\n investorPercent <= investorPercentLimit,\n \"CustomMasterChefJoeV2Timelock::withinLimits: investorPercent must not exceed limit.\"\n );\n } else if (keccak256(bytes(signature)) == keccak256(bytes(UPDATE_EMISSION_RATE_SIG))) {\n uint256 joePerSec = abi.decode(data, (uint256));\n require(\n joePerSec <= joePerSecLimit,\n \"CustomMasterChefJoeV2Timelock::withinLimits: joePerSec must not exceed limit.\"\n );\n }\n _;\n }\n\n constructor(\n address admin_,\n uint256 delay_,\n uint256 devPercentLimit_,\n uint256 treasuryPercentLimit_,\n uint256 investorPercentLimit_,\n uint256 joePerSecLimit_\n ) public {\n require(\n delay_ >= MINIMUM_DELAY,\n \"CustomMasterChefJoeV2Timelock::constructor: Delay must exceed minimum delay.\"\n );\n require(\n delay_ <= MAXIMUM_DELAY,\n \"CustomMasterChefJoeV2Timelock::constructor: Delay must not exceed maximum delay.\"\n );\n\n admin = admin_;\n delay = delay_;\n admin_initialized = false;\n devPercentLimit = devPercentLimit_;\n treasuryPercentLimit = treasuryPercentLimit_;\n investorPercentLimit = investorPercentLimit_;\n joePerSecLimit = joePerSecLimit_;\n }\n\n // XXX: function() external payable { }\n receive() external payable {}\n\n function setDelay(uint256 delay_) public {\n require(\n msg.sender == address(this),\n \"CustomMasterChefJoeV2Timelock::setDelay: Call must come from CustomMasterChefJoeV2Timelock.\"\n );\n require(delay_ >= MINIMUM_DELAY, \"CustomMasterChefJoeV2Timelock::setDelay: Delay must exceed minimum delay.\");\n require(\n delay_ <= MAXIMUM_DELAY,\n \"CustomMasterChefJoeV2Timelock::setDelay: Delay must not exceed maximum delay.\"\n );\n delay = delay_;\n\n emit NewDelay(delay);\n }\n\n function acceptAdmin() public {\n require(\n msg.sender == pendingAdmin,\n \"CustomMasterChefJoeV2Timelock::acceptAdmin: Call must come from pendingAdmin.\"\n );\n admin = msg.sender;\n pendingAdmin = address(0);\n\n emit NewAdmin(admin);\n }\n\n function setPendingAdmin(address pendingAdmin_) public {\n // allows one time setting of admin for deployment purposes\n if (admin_initialized) {\n require(\n msg.sender == address(this),\n \"CustomMasterChefJoeV2Timelock::setPendingAdmin: Call must come from CustomMasterChefJoeV2Timelock.\"\n );\n } else {\n require(\n msg.sender == admin,\n \"CustomMasterChefJoeV2Timelock::setPendingAdmin: First call must come from admin.\"\n );\n admin_initialized = true;\n }\n pendingAdmin = pendingAdmin_;\n\n emit NewPendingAdmin(pendingAdmin);\n }\n\n function queueTransaction(\n address target,\n uint256 value,\n string memory signature,\n bytes memory data,\n uint256 eta\n ) public withinLimits(signature, data) returns (bytes32) {\n require(msg.sender == admin, \"CustomMasterChefJoeV2Timelock::queueTransaction: Call must come from admin.\");\n require(\n eta >= getBlockTimestamp().add(delay),\n \"CustomMasterChefJoeV2Timelock::queueTransaction: Estimated execution block must satisfy delay.\"\n );\n\n bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));\n queuedTransactions[txHash] = true;\n\n emit QueueTransaction(txHash, target, value, signature, data, eta);\n return txHash;\n }\n\n function cancelTransaction(\n address target,\n uint256 value,\n string memory signature,\n bytes memory data,\n uint256 eta\n ) public {\n require(msg.sender == admin, \"CustomMasterChefJoeV2Timelock::cancelTransaction: Call must come from admin.\");\n\n bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));\n queuedTransactions[txHash] = false;\n\n emit CancelTransaction(txHash, target, value, signature, data, eta);\n }\n\n function executeTransaction(\n address target,\n uint256 value,\n string memory signature,\n bytes memory data,\n uint256 eta\n ) public payable returns (bytes memory) {\n require(msg.sender == admin, \"CustomMasterChefJoeV2Timelock::executeTransaction: Call must come from admin.\");\n\n bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));\n require(\n queuedTransactions[txHash],\n \"CustomMasterChefJoeV2Timelock::executeTransaction: Transaction hasn't been queued.\"\n );\n require(\n getBlockTimestamp() >= eta,\n \"CustomMasterChefJoeV2Timelock::executeTransaction: Transaction hasn't surpassed time lock.\"\n );\n require(\n getBlockTimestamp() <= eta.add(GRACE_PERIOD),\n \"CustomMasterChefJoeV2Timelock::executeTransaction: Transaction is stale.\"\n );\n\n queuedTransactions[txHash] = false;\n\n bytes memory callData;\n\n callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data);\n\n // solium-disable-next-line security/no-call-value\n (bool success, bytes memory returnData) = target.call.value(value)(callData);\n require(success, \"CustomMasterChefJoeV2Timelock::executeTransaction: Transaction execution reverted.\");\n\n emit ExecuteTransaction(txHash, target, value, signature, data, eta);\n\n return returnData;\n }\n\n function getBlockTimestamp() internal view returns (uint256) {\n // solium-disable-next-line security/no-block-members\n return block.timestamp;\n }\n}\n" + }, + "contracts/rewarders/SimpleRewarderPerSec.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\nimport \"../boringcrypto/BoringOwnable.sol\";\nimport \"../libraries/SafeERC20.sol\";\n\ninterface IRewarder {\n using SafeERC20 for IERC20;\n\n function onJoeReward(address user, uint256 newLpAmount) external;\n\n function pendingTokens(address user) external view returns (uint256 pending);\n\n function rewardToken() external view returns (IERC20);\n}\n\ninterface IMasterChefJoe {\n using SafeERC20 for IERC20;\n\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this poolInfo. SUSHI to distribute per block.\n uint256 lastRewardTimestamp; // Last block timestamp that SUSHI distribution occurs.\n uint256 accJoePerShare; // Accumulated SUSHI per share, times 1e12. See below.\n }\n\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n}\n\n/**\n * This is a sample contract to be used in the MasterChefJoe contract for partners to reward\n * stakers with their native token alongside JOE.\n *\n * It assumes no minting rights, so requires a set amount of YOUR_TOKEN to be transferred to this contract prior.\n * E.g. say you've allocated 100,000 XYZ to the JOE-XYZ farm over 30 days. Then you would need to transfer\n * 100,000 XYZ and set the block reward accordingly so it's fully distributed after 30 days.\n *\n *\n * Issue with the previous version is that this fraction, `tokenReward.mul(ACC_TOKEN_PRECISION).div(lpSupply)`,\n * can return 0 or be very inacurate with some tokens:\n * uint256 timeElapsed = block.timestamp.sub(pool.lastRewardTimestamp);\n * uint256 tokenReward = timeElapsed.mul(tokenPerSec);\n * accTokenPerShare = accTokenPerShare.add(\n * tokenReward.mul(ACC_TOKEN_PRECISION).div(lpSupply)\n * );\n * The goal is to set ACC_TOKEN_PRECISION high enough to prevent this without causing overflow too.\n */\ncontract SimpleRewarderPerSec is IRewarder, BoringOwnable, ReentrancyGuard {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n IERC20 public immutable override rewardToken;\n IERC20 public immutable lpToken;\n bool public immutable isNative;\n IMasterChefJoe public immutable MCJ;\n\n /// @notice Info of each MCJ user.\n /// `amount` LP token amount the user has provided.\n /// `rewardDebt` The amount of YOUR_TOKEN entitled to the user.\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n uint256 unpaidRewards;\n }\n\n /// @notice Info of each MCJ poolInfo.\n /// `accTokenPerShare` Amount of YOUR_TOKEN each LP token is worth.\n /// `lastRewardTimestamp` The last timestamp YOUR_TOKEN was rewarded to the poolInfo.\n struct PoolInfo {\n uint256 accTokenPerShare;\n uint256 lastRewardTimestamp;\n }\n\n /// @notice Info of the poolInfo.\n PoolInfo public poolInfo;\n /// @notice Info of each user that stakes LP tokens.\n mapping(address => UserInfo) public userInfo;\n\n uint256 public tokenPerSec;\n\n uint256 private ACC_TOKEN_PRECISION;\n\n event OnReward(address indexed user, uint256 amount);\n event RewardRateUpdated(uint256 oldRate, uint256 newRate);\n\n modifier onlyMCJ() {\n require(msg.sender == address(MCJ), \"onlyMCJ: only MasterChefJoe can call this function\");\n _;\n }\n\n constructor(\n IERC20 _rewardToken,\n IERC20 _lpToken,\n uint256 _tokenPerSec,\n IMasterChefJoe _MCJ,\n bool _isNative\n ) public {\n require(Address.isContract(address(_rewardToken)), \"constructor: reward token must be a valid contract\");\n require(Address.isContract(address(_lpToken)), \"constructor: LP token must be a valid contract\");\n require(Address.isContract(address(_MCJ)), \"constructor: MasterChefJoe must be a valid contract\");\n require(_tokenPerSec <= 1e30, \"constructor: token per seconds can't be greater than 1e30\");\n\n rewardToken = _rewardToken;\n lpToken = _lpToken;\n tokenPerSec = _tokenPerSec;\n MCJ = _MCJ;\n isNative = _isNative;\n poolInfo = PoolInfo({lastRewardTimestamp: block.timestamp, accTokenPerShare: 0});\n\n // Given the fraction, tokenReward * ACC_TOKEN_PRECISION / lpSupply, we consider\n // several edge cases.\n\n // Edge case n1: maximize the numerator, minimize the denominator.\n // `lpSupply` = 1 WEI\n // `tokenPerSec` = 1e(30)\n // `timeElapsed` = 31 years, i.e. 1e9 seconds\n // result = 1e9 * 1e30 * 1e36 / 1\n // = 1e75\n // (No overflow as max uint256 is 1.15e77).\n // PS: This will overflow when `timeElapsed` becomes greater than 1e11, i.e. in more than 3_000 years\n // so it should be fine.\n //\n // Edge case n2: minimize the numerator, maximize the denominator.\n // `lpSupply` = max(uint112) = 1e34\n // `tokenPerSec` = 1 WEI\n // `timeElapsed` = 1 second\n // result = 1 * 1 * 1e36 / 1e34\n // = 1e2\n // (Not rounded to zero, therefore ACC_TOKEN_PRECISION = 1e36 is safe)\n ACC_TOKEN_PRECISION = 1e36;\n }\n\n /// @notice Update reward variables of the given poolInfo.\n /// @return pool Returns the pool that was updated.\n function updatePool() public returns (PoolInfo memory pool) {\n pool = poolInfo;\n\n if (block.timestamp > pool.lastRewardTimestamp) {\n uint256 lpSupply = lpToken.balanceOf(address(MCJ));\n\n if (lpSupply > 0) {\n uint256 timeElapsed = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 tokenReward = timeElapsed.mul(tokenPerSec);\n pool.accTokenPerShare = pool.accTokenPerShare.add((tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply));\n }\n\n pool.lastRewardTimestamp = block.timestamp;\n poolInfo = pool;\n }\n }\n\n /// @notice Sets the distribution reward rate. This will also update the poolInfo.\n /// @param _tokenPerSec The number of tokens to distribute per second\n function setRewardRate(uint256 _tokenPerSec) external onlyOwner {\n updatePool();\n\n uint256 oldRate = tokenPerSec;\n tokenPerSec = _tokenPerSec;\n\n emit RewardRateUpdated(oldRate, _tokenPerSec);\n }\n\n /// @notice Function called by MasterChefJoe whenever staker claims JOE harvest. Allows staker to also receive a 2nd reward token.\n /// @param _user Address of user\n /// @param _lpAmount Number of LP tokens the user has\n function onJoeReward(address _user, uint256 _lpAmount) external override onlyMCJ nonReentrant {\n updatePool();\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n uint256 pending;\n if (user.amount > 0) {\n pending = (user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt).add(\n user.unpaidRewards\n );\n\n if (isNative) {\n uint256 balance = address(this).balance;\n if (pending > balance) {\n (bool success, ) = _user.call.value(balance)(\"\");\n require(success, \"Transfer failed\");\n user.unpaidRewards = pending - balance;\n } else {\n (bool success, ) = _user.call.value(pending)(\"\");\n require(success, \"Transfer failed\");\n user.unpaidRewards = 0;\n }\n } else {\n uint256 balance = rewardToken.balanceOf(address(this));\n if (pending > balance) {\n rewardToken.safeTransfer(_user, balance);\n user.unpaidRewards = pending - balance;\n } else {\n rewardToken.safeTransfer(_user, pending);\n user.unpaidRewards = 0;\n }\n }\n }\n\n user.amount = _lpAmount;\n user.rewardDebt = user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION;\n emit OnReward(_user, pending - user.unpaidRewards);\n }\n\n /// @notice View function to see pending tokens\n /// @param _user Address of user.\n /// @return pending reward for a given user.\n function pendingTokens(address _user) external view override returns (uint256 pending) {\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n\n uint256 accTokenPerShare = pool.accTokenPerShare;\n uint256 lpSupply = lpToken.balanceOf(address(MCJ));\n\n if (block.timestamp > pool.lastRewardTimestamp && lpSupply != 0) {\n uint256 timeElapsed = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 tokenReward = timeElapsed.mul(tokenPerSec);\n accTokenPerShare = accTokenPerShare.add(tokenReward.mul(ACC_TOKEN_PRECISION).div(lpSupply));\n }\n\n pending = (user.amount.mul(accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt).add(\n user.unpaidRewards\n );\n }\n\n /// @notice In case rewarder is stopped before emissions finished, this function allows\n /// withdrawal of remaining tokens.\n function emergencyWithdraw() public onlyOwner {\n if (isNative) {\n (bool success, ) = msg.sender.call.value(address(this).balance)(\"\");\n require(success, \"Transfer failed\");\n } else {\n rewardToken.safeTransfer(address(msg.sender), rewardToken.balanceOf(address(this)));\n }\n }\n\n /// @notice View function to see balance of reward token.\n function balance() external view returns (uint256) {\n if (isNative) {\n return address(this).balance;\n } else {\n return rewardToken.balanceOf(address(this));\n }\n }\n\n /// @notice payable function needed to receive AVAX\n receive() external payable {}\n}\n" + }, + "@openzeppelin/contracts/utils/ReentrancyGuard.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n constructor () internal {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and make it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n}\n" + }, + "contracts/boringcrypto/BoringOwnable.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\n// Audit on 5-Jan-2021 by Keno and BoringCrypto\n// Source: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol + Claimable.sol\n// Edited by BoringCrypto\n\ncontract BoringOwnableData {\n address public owner;\n address public pendingOwner;\n}\n\ncontract BoringOwnable is BoringOwnableData {\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /// @notice `owner` defaults to msg.sender on construction.\n constructor() public {\n owner = msg.sender;\n emit OwnershipTransferred(address(0), msg.sender);\n }\n\n /// @notice Transfers ownership to `newOwner`. Either directly or claimable by the new pending owner.\n /// Can only be invoked by the current `owner`.\n /// @param newOwner Address of the new owner.\n /// @param direct True if `newOwner` should be set immediately. False if `newOwner` needs to use `claimOwnership`.\n /// @param renounce Allows the `newOwner` to be `address(0)` if `direct` and `renounce` is True. Has no effect otherwise.\n function transferOwnership(\n address newOwner,\n bool direct,\n bool renounce\n ) public onlyOwner {\n if (direct) {\n // Checks\n require(newOwner != address(0) || renounce, \"Ownable: zero address\");\n\n // Effects\n emit OwnershipTransferred(owner, newOwner);\n owner = newOwner;\n pendingOwner = address(0);\n } else {\n // Effects\n pendingOwner = newOwner;\n }\n }\n\n /// @notice Needs to be called by `pendingOwner` to claim ownership.\n function claimOwnership() public {\n address _pendingOwner = pendingOwner;\n\n // Checks\n require(msg.sender == _pendingOwner, \"Ownable: caller != pending owner\");\n\n // Effects\n emit OwnershipTransferred(owner, _pendingOwner);\n owner = _pendingOwner;\n pendingOwner = address(0);\n }\n\n /// @notice Only allows the `owner` to execute the function.\n modifier onlyOwner() {\n require(msg.sender == owner, \"Ownable: caller is not the owner\");\n _;\n }\n}\n" + }, + "contracts/traderjoe/FarmLensV2.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\nimport \"../libraries/SafeMath.sol\";\nimport \"../libraries/SafeERC20.sol\";\n\nimport \"./interfaces/IERC20.sol\";\nimport \"./interfaces/IJoeERC20.sol\";\nimport \"./interfaces/IJoePair.sol\";\nimport \"./interfaces/IJoeFactory.sol\";\n\ninterface IMasterChef {\n struct PoolInfo {\n IJoeERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\n }\n\n function poolLength() external view returns (uint256);\n\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function joePerSec() external view returns (uint256);\n}\n\ninterface IBoostedMasterchef {\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n uint256 factor;\n }\n\n struct PoolInfo {\n IERC20 lpToken;\n uint96 allocPoint;\n uint256 accJoePerShare;\n uint256 accJoePerFactorPerShare;\n uint64 lastRewardTimestamp;\n address rewarder;\n uint32 veJoeShareBp;\n uint256 totalFactor;\n uint256 totalLpSupply;\n }\n\n function userInfo(uint256 _pid, address user) external view returns (UserInfo memory);\n\n function pendingTokens(uint256 _pid, address user)\n external\n view\n returns (\n uint256,\n address,\n string memory,\n uint256\n );\n\n function poolLength() external view returns (uint256);\n\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function joePerSec() external view returns (uint256);\n}\n\ncontract FarmLensV2 {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n struct FarmInfo {\n uint256 id;\n uint256 allocPoint;\n address lpAddress;\n address token0Address;\n address token1Address;\n string token0Symbol;\n string token1Symbol;\n uint256 reserveUsd;\n uint256 totalSupplyScaled;\n address chefAddress;\n uint256 chefBalanceScaled;\n uint256 chefTotalAlloc;\n uint256 chefJoePerSec;\n }\n\n struct FarmInfoBMCJ {\n uint256 id;\n uint256 allocPoint;\n address lpAddress;\n address token0Address;\n address token1Address;\n string token0Symbol;\n string token1Symbol;\n uint256 reserveUsd;\n uint256 totalSupplyScaled;\n address chefAddress;\n uint256 chefBalanceScaled;\n uint256 chefTotalAlloc;\n uint256 chefJoePerSec;\n uint256 baseApr;\n uint256 averageBoostedApr;\n uint256 veJoeShareBp;\n uint256 joePriceUsd;\n\n uint256 userLp;\n uint256 userPendingJoe;\n uint256 userBoostedApr;\n uint256 userFactorShare;\n }\n\n struct AllFarmData {\n uint256 avaxPriceUsd;\n uint256 joePriceUsd;\n uint256 totalAllocChefV2;\n uint256 totalAllocChefV3;\n uint256 totalAllocBMCJ;\n uint256 joePerSecChefV2;\n uint256 joePerSecChefV3;\n uint256 joePerSecBMCJ;\n FarmInfo[] farmInfosV2;\n FarmInfo[] farmInfosV3;\n FarmInfoBMCJ[] farmInfosBMCJ;\n }\n\n struct GlobalInfo {\n address chef;\n uint256 totalAlloc;\n uint256 joePerSec;\n }\n\n /// @dev 365 * 86400, hard coding it for gas optimisation\n uint256 private constant SEC_PER_YEAR = 31536000;\n uint256 private constant BP_PRECISION = 10_000;\n uint256 private constant PRECISION = 1e18;\n\n address public immutable joe; // 0x6e84a6216eA6dACC71eE8E6b0a5B7322EEbC0fDd;\n address public immutable wavax; // 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7;\n IJoePair public immutable wavaxUsdte; // 0xeD8CBD9F0cE3C6986b22002F03c6475CEb7a6256\n IJoePair public immutable wavaxUsdce; // 0xA389f9430876455C36478DeEa9769B7Ca4E3DDB1\n IJoePair public immutable wavaxUsdc; // 0xf4003f4efbe8691b60249e6afbd307abe7758adb\n IJoeFactory public immutable joeFactory; // 0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10\n IMasterChef public immutable chefv2; // 0xd6a4F121CA35509aF06A0Be99093d08462f53052\n IMasterChef public immutable chefv3; // 0x188bED1968b795d5c9022F6a0bb5931Ac4c18F00\n IBoostedMasterchef public immutable bmcj; // Not deployed yet\n bool private immutable isWavaxToken1InWavaxUsdte;\n bool private immutable isWavaxToken1InWavaxUsdce;\n bool private immutable isWavaxToken1InWavaxUsdc;\n\n constructor(\n address _joe,\n address _wavax,\n IJoePair _wavaxUsdte,\n IJoePair _wavaxUsdce,\n IJoePair _wavaxUsdc,\n IJoeFactory _joeFactory,\n IMasterChef _chefv2,\n IMasterChef _chefv3,\n IBoostedMasterchef _bmcj\n ) public {\n joe = _joe;\n wavax = _wavax;\n wavaxUsdte = _wavaxUsdte;\n wavaxUsdce = _wavaxUsdce;\n wavaxUsdc = _wavaxUsdc;\n joeFactory = _joeFactory;\n chefv2 = _chefv2;\n chefv3 = _chefv3;\n bmcj = _bmcj;\n\n isWavaxToken1InWavaxUsdte = _wavaxUsdte.token1() == _wavax;\n isWavaxToken1InWavaxUsdce = _wavaxUsdce.token1() == _wavax;\n isWavaxToken1InWavaxUsdc = _wavaxUsdc.token1() == _wavax;\n }\n\n /// @notice Returns the price of avax in Usd\n /// @return uint256 the avax price, scaled to 18 decimals\n function getAvaxPrice() external view returns (uint256) {\n return _getAvaxPrice();\n }\n\n /// @notice Returns the derived price of token, it needs to be paired with wavax\n /// @param token The address of the token\n /// @return uint256 the token derived price, scaled to 18 decimals\n function getDerivedAvaxPriceOfToken(address token) external view returns (uint256) {\n return _getDerivedAvaxPriceOfToken(token);\n }\n\n /// @notice Returns the Usd price of token, it needs to be paired with wavax\n /// @param token The address of the token\n /// @return uint256 the Usd price of token, scaled to 18 decimals\n function getTokenPrice(address token) external view returns (uint256) {\n return _getDerivedAvaxPriceOfToken(token).mul(_getAvaxPrice()) / 1e18;\n }\n\n /// @notice Returns the farm pairs data for MCV2 and MCV3\n /// @param chef The address of the MasterChef\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\n function getMCFarmInfos(IMasterChef chef, uint256[] calldata whitelistedPids)\n external\n view\n returns (FarmInfo[] memory)\n {\n require(chef == chefv2 || chef == chefv3, \"FarmLensV2: only for MCV2 and MCV3\");\n\n uint256 avaxPrice = _getAvaxPrice();\n return _getMCFarmInfos(chef, avaxPrice, whitelistedPids);\n }\n\n /// @notice Returns the farm pairs data for BoostedMasterChefJoe\n /// @param chef The address of the MasterChef\n /// @param user The address of the user, if address(0), returns global info\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\n /// @return FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\n function getBMCJFarmInfos(\n IBoostedMasterchef chef,\n address user,\n uint256[] calldata whitelistedPids\n ) external view returns (FarmInfoBMCJ[] memory) {\n require(chef == bmcj, \"FarmLensV2: Only for BMCJ\");\n\n uint256 avaxPrice = _getAvaxPrice();\n uint256 joePrice = _getDerivedAvaxPriceOfToken(joe).mul(avaxPrice) / PRECISION;\n return _getBMCJFarmInfos(avaxPrice, joePrice, user, whitelistedPids);\n }\n\n /// @notice Get all data needed for useFarms hook.\n /// @param whitelistedPidsV2 Array of all ids of pools that are whitelisted in chefV2\n /// @param whitelistedPidsV3 Array of all ids of pools that are whitelisted in chefV3\n /// @param whitelistedPidsBMCJ Array of all ids of pools that are whitelisted in BMCJ\n /// @param user The address of the user, if address(0), returns global info\n /// @return AllFarmData The information of all the whitelisted farms of MCV2, MCV3 and BMCJ\n function getAllFarmData(\n uint256[] calldata whitelistedPidsV2,\n uint256[] calldata whitelistedPidsV3,\n uint256[] calldata whitelistedPidsBMCJ,\n address user\n ) external view returns (AllFarmData memory) {\n AllFarmData memory allFarmData;\n\n uint256 avaxPrice = _getAvaxPrice();\n uint256 joePrice = _getDerivedAvaxPriceOfToken(joe).mul(avaxPrice) / PRECISION;\n\n allFarmData.avaxPriceUsd = avaxPrice;\n allFarmData.joePriceUsd = joePrice;\n\n allFarmData.totalAllocChefV2 = chefv2.totalAllocPoint();\n allFarmData.joePerSecChefV2 = chefv2.joePerSec();\n\n allFarmData.totalAllocChefV3 = chefv3.totalAllocPoint();\n allFarmData.joePerSecChefV3 = chefv3.joePerSec();\n\n allFarmData.totalAllocBMCJ = bmcj.totalAllocPoint();\n allFarmData.joePerSecBMCJ = bmcj.joePerSec();\n\n allFarmData.farmInfosV2 = _getMCFarmInfos(chefv2, avaxPrice, whitelistedPidsV2);\n allFarmData.farmInfosV3 = _getMCFarmInfos(chefv3, avaxPrice, whitelistedPidsV3);\n allFarmData.farmInfosBMCJ = _getBMCJFarmInfos(avaxPrice, joePrice, user, whitelistedPidsBMCJ);\n\n return allFarmData;\n }\n\n /// @notice Returns the price of avax in Usd internally\n /// @return uint256 the avax price, scaled to 18 decimals\n function _getAvaxPrice() private view returns (uint256) {\n return\n _getDerivedTokenPriceOfPair(wavaxUsdte, isWavaxToken1InWavaxUsdte)\n .add(_getDerivedTokenPriceOfPair(wavaxUsdce, isWavaxToken1InWavaxUsdce))\n .add(_getDerivedTokenPriceOfPair(wavaxUsdc, isWavaxToken1InWavaxUsdc)) / 3;\n }\n\n /// @notice Returns the derived price of token in the other token\n /// @param pair The address of the pair\n /// @param derivedtoken0 If price should be derived from token0 if true, or token1 if false\n /// @return uint256 the derived price, scaled to 18 decimals\n function _getDerivedTokenPriceOfPair(IJoePair pair, bool derivedtoken0) private view returns (uint256) {\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n uint256 decimals0 = IERC20(pair.token0()).safeDecimals();\n uint256 decimals1 = IERC20(pair.token1()).safeDecimals();\n\n if (derivedtoken0) {\n return _scaleTo(reserve0, decimals1.add(18).sub(decimals0)).div(reserve1);\n } else {\n return _scaleTo(reserve1, decimals0.add(18).sub(decimals1)).div(reserve0);\n }\n }\n\n /// @notice Returns the derived price of token, it needs to be paired with wavax\n /// @param token The address of the token\n /// @return uint256 the token derived price, scaled to 18 decimals\n function _getDerivedAvaxPriceOfToken(address token) private view returns (uint256) {\n if (token == wavax) {\n return PRECISION;\n }\n IJoePair pair = IJoePair(joeFactory.getPair(token, wavax));\n if (address(pair) == address(0)) {\n return 0;\n }\n // instead of testing wavax == pair.token0(), we do the opposite to save gas\n return _getDerivedTokenPriceOfPair(pair, token == pair.token1());\n }\n\n /// @notice Returns the amount scaled to decimals\n /// @param amount The amount\n /// @param decimals The decimals to scale `amount`\n /// @return uint256 The amount scaled to decimals\n function _scaleTo(uint256 amount, uint256 decimals) private pure returns (uint256) {\n if (decimals == 0) return amount;\n return amount.mul(10**decimals);\n }\n\n /// @notice Returns the derived avax liquidity, at least one of the token needs to be paired with wavax\n /// @param pair The address of the pair\n /// @return uint256 the derived price of pair's liquidity, scaled to 18 decimals\n function _getDerivedAvaxLiquidityOfPair(IJoePair pair) private view returns (uint256) {\n address _wavax = wavax;\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n IERC20 token0 = IERC20(pair.token0());\n IERC20 token1 = IERC20(pair.token1());\n uint256 decimals0 = token0.safeDecimals();\n uint256 decimals1 = token1.safeDecimals();\n\n reserve0 = _scaleTo(reserve0, uint256(18).sub(decimals0));\n reserve1 = _scaleTo(reserve1, uint256(18).sub(decimals1));\n\n uint256 token0DerivedAvaxPrice;\n uint256 token1DerivedAvaxPrice;\n if (address(token0) == _wavax) {\n token0DerivedAvaxPrice = PRECISION;\n token1DerivedAvaxPrice = _getDerivedTokenPriceOfPair(pair, true);\n } else if (address(token1) == _wavax) {\n token0DerivedAvaxPrice = _getDerivedTokenPriceOfPair(pair, false);\n token1DerivedAvaxPrice = PRECISION;\n } else {\n token0DerivedAvaxPrice = _getDerivedAvaxPriceOfToken(address(token0));\n token1DerivedAvaxPrice = _getDerivedAvaxPriceOfToken(address(token1));\n // If one token isn't paired with wavax, then we hope that the second one is.\n // E.g, TOKEN/UsdC, token might not be paired with wavax, but UsdC is.\n // If both aren't paired with wavax, return 0\n if (token0DerivedAvaxPrice == 0) return reserve1.mul(token1DerivedAvaxPrice).mul(2) / PRECISION;\n if (token1DerivedAvaxPrice == 0) return reserve0.mul(token0DerivedAvaxPrice).mul(2) / PRECISION;\n }\n return reserve0.mul(token0DerivedAvaxPrice).add(reserve1.mul(token1DerivedAvaxPrice)) / PRECISION;\n }\n\n /// @notice Private function to return the farm pairs data for a given MasterChef (V2 or V3)\n /// @param chef The address of the MasterChef\n /// @param avaxPrice The avax price as a parameter to save gas\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\n function _getMCFarmInfos(\n IMasterChef chef,\n uint256 avaxPrice,\n uint256[] calldata whitelistedPids\n ) private view returns (FarmInfo[] memory) {\n uint256 whitelistLength = whitelistedPids.length;\n FarmInfo[] memory farmInfos = new FarmInfo[](whitelistLength);\n\n uint256 chefTotalAlloc = chef.totalAllocPoint();\n uint256 chefJoePerSec = chef.joePerSec();\n\n for (uint256 i; i < whitelistLength; i++) {\n uint256 pid = whitelistedPids[i];\n IMasterChef.PoolInfo memory pool = chef.poolInfo(pid);\n\n farmInfos[i] = _getMCFarmInfo(\n chef,\n avaxPrice,\n pid,\n IJoePair(address(pool.lpToken)),\n pool.allocPoint,\n chefTotalAlloc,\n chefJoePerSec\n );\n }\n\n return farmInfos;\n }\n\n /// @notice Helper function to return the farm info of a given pool\n /// @param chef The address of the MasterChef\n /// @param avaxPrice The avax price as a parameter to save gas\n /// @param pid The pid of the pool\n /// @param lpToken The lpToken of the pool\n /// @param allocPoint The allocPoint of the pool\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\n function _getMCFarmInfo(\n IMasterChef chef,\n uint256 avaxPrice,\n uint256 pid,\n IJoePair lpToken,\n uint256 allocPoint,\n uint256 totalAllocPoint,\n uint256 chefJoePerSec\n ) private view returns (FarmInfo memory) {\n uint256 decimals = lpToken.decimals();\n uint256 totalSupplyScaled = _scaleTo(lpToken.totalSupply(), 18 - decimals);\n uint256 chefBalanceScaled = _scaleTo(lpToken.balanceOf(address(chef)), 18 - decimals);\n uint256 reserveUsd = _getDerivedAvaxLiquidityOfPair(lpToken).mul(avaxPrice) / PRECISION;\n IERC20 token0 = IERC20(lpToken.token0());\n IERC20 token1 = IERC20(lpToken.token1());\n\n return\n FarmInfo({\n id: pid,\n allocPoint: allocPoint,\n lpAddress: address(lpToken),\n token0Address: address(token0),\n token1Address: address(token1),\n token0Symbol: token0.safeSymbol(),\n token1Symbol: token1.safeSymbol(),\n reserveUsd: reserveUsd,\n totalSupplyScaled: totalSupplyScaled,\n chefBalanceScaled: chefBalanceScaled,\n chefAddress: address(chef),\n chefTotalAlloc: totalAllocPoint,\n chefJoePerSec: chefJoePerSec\n });\n }\n\n /// @notice Private function to return the farm pairs data for boostedMasterChef\n /// @param avaxPrice The avax price as a parameter to save gas\n /// @param joePrice The joe price as a parameter to save gas\n /// @param user The address of the user, if address(0), returns global info\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\n /// @return FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\n function _getBMCJFarmInfos(\n uint256 avaxPrice,\n uint256 joePrice,\n address user,\n uint256[] calldata whitelistedPids\n ) private view returns (FarmInfoBMCJ[] memory) {\n GlobalInfo memory globalInfo = GlobalInfo(address(bmcj), bmcj.totalAllocPoint(), bmcj.joePerSec());\n\n uint256 whitelistLength = whitelistedPids.length;\n FarmInfoBMCJ[] memory farmInfos = new FarmInfoBMCJ[](whitelistLength);\n\n for (uint256 i; i < whitelistLength; i++) {\n uint256 pid = whitelistedPids[i];\n IBoostedMasterchef.PoolInfo memory pool = IBoostedMasterchef(globalInfo.chef).poolInfo(pid);\n IBoostedMasterchef.UserInfo memory userInfo;\n userInfo = IBoostedMasterchef(globalInfo.chef).userInfo(pid, user);\n\n farmInfos[i].id = pid;\n farmInfos[i].chefAddress = globalInfo.chef;\n farmInfos[i].chefTotalAlloc = globalInfo.totalAlloc;\n farmInfos[i].chefJoePerSec = globalInfo.joePerSec;\n farmInfos[i].joePriceUsd = joePrice;\n _getBMCJFarmInfo(\n avaxPrice,\n globalInfo.joePerSec.mul(joePrice) / PRECISION,\n user,\n farmInfos[i],\n pool,\n userInfo\n );\n }\n\n return farmInfos;\n }\n\n /// @notice Helper function to return the farm info of a given pool of BMCJ\n /// @param avaxPrice The avax price as a parameter to save gas\n /// @param UsdPerSec The Usd per sec emitted to BMCJ\n /// @param userAddress The address of the user\n /// @param farmInfo The farmInfo of that pool\n /// @param user The user information\n function _getBMCJFarmInfo(\n uint256 avaxPrice,\n uint256 UsdPerSec,\n address userAddress,\n FarmInfoBMCJ memory farmInfo,\n IBoostedMasterchef.PoolInfo memory pool,\n IBoostedMasterchef.UserInfo memory user\n ) private view {\n {\n IJoePair lpToken = IJoePair(address(pool.lpToken));\n IERC20 token0 = IERC20(lpToken.token0());\n IERC20 token1 = IERC20(lpToken.token1());\n\n farmInfo.allocPoint = pool.allocPoint;\n farmInfo.lpAddress = address(lpToken);\n farmInfo.token0Address = address(token0);\n farmInfo.token1Address = address(token1);\n farmInfo.token0Symbol = token0.safeSymbol();\n farmInfo.token1Symbol = token1.safeSymbol();\n farmInfo.reserveUsd = _getDerivedAvaxLiquidityOfPair(lpToken).mul(avaxPrice) / PRECISION;\n // LP is in 18 decimals, so it's already scaled for JLP\n farmInfo.totalSupplyScaled = lpToken.totalSupply();\n farmInfo.chefBalanceScaled = pool.totalLpSupply;\n farmInfo.userLp = user.amount;\n farmInfo.veJoeShareBp = pool.veJoeShareBp;\n (farmInfo.userPendingJoe, , , ) = bmcj.pendingTokens(farmInfo.id, userAddress);\n }\n\n if (\n pool.totalLpSupply != 0 &&\n farmInfo.totalSupplyScaled != 0 &&\n farmInfo.chefTotalAlloc != 0 &&\n farmInfo.reserveUsd != 0\n ) {\n uint256 poolUsdPerYear = UsdPerSec.mul(pool.allocPoint).mul(SEC_PER_YEAR) / farmInfo.chefTotalAlloc;\n\n uint256 poolReserveUsd = farmInfo.reserveUsd.mul(farmInfo.chefBalanceScaled) / farmInfo.totalSupplyScaled;\n\n if (poolReserveUsd == 0) return;\n\n farmInfo.baseApr =\n poolUsdPerYear.mul(BP_PRECISION - pool.veJoeShareBp).mul(PRECISION) /\n poolReserveUsd /\n BP_PRECISION;\n\n if (pool.totalFactor != 0) {\n farmInfo.averageBoostedApr =\n poolUsdPerYear.mul(pool.veJoeShareBp).mul(PRECISION) /\n poolReserveUsd /\n BP_PRECISION;\n\n if (user.amount != 0 && user.factor != 0) {\n uint256 userLpUsd = user.amount.mul(farmInfo.reserveUsd) / pool.totalLpSupply;\n\n farmInfo.userBoostedApr =\n poolUsdPerYear.mul(pool.veJoeShareBp).mul(user.factor).div(pool.totalFactor).mul(PRECISION) /\n userLpUsd /\n BP_PRECISION;\n\n farmInfo.userFactorShare = user.factor.mul(PRECISION) / pool.totalFactor;\n }\n }\n }\n }\n}\n" + }, + "contracts/traderjoe/interfaces/IJoeERC20.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\ninterface IJoeERC20 {\n event Approval(address indexed owner, address indexed spender, uint256 value);\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n function name() external pure returns (string memory);\n\n function symbol() external pure returns (string memory);\n\n function decimals() external pure returns (uint8);\n\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address owner) external view returns (uint256);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 value) external returns (bool);\n\n function transfer(address to, uint256 value) external returns (bool);\n\n function transferFrom(\n address from,\n address to,\n uint256 value\n ) external returns (bool);\n\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n\n function PERMIT_TYPEHASH() external pure returns (bytes32);\n\n function nonces(address owner) external view returns (uint256);\n\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n}\n" + }, + "contracts/traderjoe/FarmLens.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\nimport \"../libraries/SafeMath.sol\";\nimport \"../libraries/SafeERC20.sol\";\n\nimport \"../interfaces/IERC20.sol\";\nimport \"./interfaces/IJoeERC20.sol\";\nimport \"./interfaces/IJoePair.sol\";\nimport \"./interfaces/IJoeFactory.sol\";\n\nimport \"../boringcrypto/BoringOwnable.sol\";\n\ninterface IMasterChef {\n struct PoolInfo {\n IJoeERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\n }\n\n function poolLength() external view returns (uint256);\n\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function joePerSec() external view returns (uint256);\n}\n\ncontract FarmLens is BoringOwnable {\n using SafeMath for uint256;\n\n address public joe; // 0x6e84a6216eA6dACC71eE8E6b0a5B7322EEbC0fDd;\n address public wavax; // 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7;\n address public wavaxUsdt; // 0xeD8CBD9F0cE3C6986b22002F03c6475CEb7a6256\n address public wavaxUsdc; // 0x87Dee1cC9FFd464B79e058ba20387c1984aed86a\n address public wavaxDai; // 0xA389f9430876455C36478DeEa9769B7Ca4E3DDB1\n IJoeFactory public joeFactory; // IJoeFactory(0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10);\n IMasterChef public chefv2; //0xd6a4F121CA35509aF06A0Be99093d08462f53052\n IMasterChef public chefv3; //0x188bED1968b795d5c9022F6a0bb5931Ac4c18F00\n\n constructor(\n address joe_,\n address wavax_,\n address wavaxUsdt_,\n address wavaxUsdc_,\n address wavaxDai_,\n IJoeFactory joeFactory_,\n IMasterChef chefv2_,\n IMasterChef chefv3_\n ) public {\n joe = joe_;\n wavax = wavax_;\n wavaxUsdt = wavaxUsdt_;\n wavaxUsdc = wavaxUsdc_;\n wavaxDai = wavaxDai_;\n joeFactory = IJoeFactory(joeFactory_);\n chefv2 = chefv2_;\n chefv3 = chefv3_;\n }\n\n /// @notice Returns price of avax in usd.\n function getAvaxPrice() public view returns (uint256) {\n uint256 priceFromWavaxUsdt = _getAvaxPrice(IJoePair(wavaxUsdt)); // 18\n uint256 priceFromWavaxUsdc = _getAvaxPrice(IJoePair(wavaxUsdc)); // 18\n uint256 priceFromWavaxDai = _getAvaxPrice(IJoePair(wavaxDai)); // 18\n\n uint256 sumPrice = priceFromWavaxUsdt.add(priceFromWavaxUsdc).add(priceFromWavaxDai); // 18\n uint256 avaxPrice = sumPrice / 3; // 18\n return avaxPrice; // 18\n }\n\n /// @notice Returns value of wavax in units of stablecoins per wavax.\n /// @param pair A wavax-stablecoin pair.\n function _getAvaxPrice(IJoePair pair) private view returns (uint256) {\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n\n if (pair.token0() == wavax) {\n reserve1 = reserve1.mul(_tokenDecimalsMultiplier(pair.token1())); // 18\n return (reserve1.mul(1e18)) / reserve0; // 18\n } else {\n reserve0 = reserve0.mul(_tokenDecimalsMultiplier(pair.token0())); // 18\n return (reserve0.mul(1e18)) / reserve1; // 18\n }\n }\n\n /// @notice Get the price of a token in Usd.\n /// @param tokenAddress Address of the token.\n function getPriceInUsd(address tokenAddress) public view returns (uint256) {\n return (getAvaxPrice().mul(getPriceInAvax(tokenAddress))) / 1e18; // 18\n }\n\n /// @notice Get the price of a token in Avax.\n /// @param tokenAddress Address of the token.\n /// @dev Need to be aware of decimals here, not always 18, it depends on the token.\n function getPriceInAvax(address tokenAddress) public view returns (uint256) {\n if (tokenAddress == wavax) {\n return 1e18;\n }\n\n IJoePair pair = IJoePair(joeFactory.getPair(tokenAddress, wavax));\n\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n address token0Address = pair.token0();\n address token1Address = pair.token1();\n\n if (token0Address == wavax) {\n reserve1 = reserve1.mul(_tokenDecimalsMultiplier(token1Address)); // 18\n return (reserve0.mul(1e18)) / reserve1; // 18\n } else {\n reserve0 = reserve0.mul(_tokenDecimalsMultiplier(token0Address)); // 18\n return (reserve1.mul(1e18)) / reserve0; // 18\n }\n }\n\n /// @notice Calculates the multiplier needed to scale a token's numerical field to 18 decimals.\n /// @param tokenAddress Address of the token.\n function _tokenDecimalsMultiplier(address tokenAddress) private pure returns (uint256) {\n uint256 decimalsNeeded = 18 - IJoeERC20(tokenAddress).decimals();\n return 1 * (10**decimalsNeeded);\n }\n\n /// @notice Calculates the reserve of a pair in usd.\n /// @param pair Pair for which the reserve will be calculated.\n function getReserveUsd(IJoePair pair) public view returns (uint256) {\n address token0Address = pair.token0();\n address token1Address = pair.token1();\n\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n\n reserve0 = reserve0.mul(_tokenDecimalsMultiplier(token0Address)); // 18\n reserve1 = reserve1.mul(_tokenDecimalsMultiplier(token1Address)); // 18\n\n uint256 token0PriceInAvax = getPriceInAvax(token0Address); // 18\n uint256 token1PriceInAvax = getPriceInAvax(token1Address); // 18\n uint256 reserve0Avax = reserve0.mul(token0PriceInAvax); // 36;\n uint256 reserve1Avax = reserve1.mul(token1PriceInAvax); // 36;\n uint256 reserveAvax = (reserve0Avax.add(reserve1Avax)) / 1e18; // 18\n uint256 reserveUsd = (reserveAvax.mul(getAvaxPrice())) / 1e18; // 18\n\n return reserveUsd; // 18\n }\n\n struct FarmPair {\n uint256 id;\n uint256 allocPoint;\n address lpAddress;\n address token0Address;\n address token1Address;\n string token0Symbol;\n string token1Symbol;\n uint256 reserveUsd;\n uint256 totalSupplyScaled;\n address chefAddress;\n uint256 chefBalanceScaled;\n uint256 chefTotalAlloc;\n uint256 chefJoePerSec;\n }\n\n /// @notice Gets the farm pair data for a given MasterChef.\n /// @param chefAddress The address of the MasterChef.\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned.\n function getFarmPairs(address chefAddress, uint256[] calldata whitelistedPids)\n public\n view\n returns (FarmPair[] memory)\n {\n IMasterChef chef = IMasterChef(chefAddress);\n\n uint256 whitelistLength = whitelistedPids.length;\n FarmPair[] memory farmPairs = new FarmPair[](whitelistLength);\n\n for (uint256 i = 0; i < whitelistLength; i++) {\n IMasterChef.PoolInfo memory pool = chef.poolInfo(whitelistedPids[i]);\n IJoePair lpToken = IJoePair(address(pool.lpToken));\n\n //get pool information\n farmPairs[i].id = whitelistedPids[i];\n farmPairs[i].allocPoint = pool.allocPoint;\n\n // get pair information\n address lpAddress = address(lpToken);\n address token0Address = lpToken.token0();\n address token1Address = lpToken.token1();\n farmPairs[i].lpAddress = lpAddress;\n farmPairs[i].token0Address = token0Address;\n farmPairs[i].token1Address = token1Address;\n farmPairs[i].token0Symbol = IJoeERC20(token0Address).symbol();\n farmPairs[i].token1Symbol = IJoeERC20(token1Address).symbol();\n\n // calculate reserveUsd of lp\n farmPairs[i].reserveUsd = getReserveUsd(lpToken); // 18\n\n // calculate total supply of lp\n farmPairs[i].totalSupplyScaled = lpToken.totalSupply().mul(_tokenDecimalsMultiplier(lpAddress));\n\n // get masterChef data\n uint256 balance = lpToken.balanceOf(chefAddress);\n farmPairs[i].chefBalanceScaled = balance.mul(_tokenDecimalsMultiplier(lpAddress));\n farmPairs[i].chefAddress = chefAddress;\n farmPairs[i].chefTotalAlloc = chef.totalAllocPoint();\n farmPairs[i].chefJoePerSec = chef.joePerSec();\n }\n\n return farmPairs;\n }\n\n struct AllFarmData {\n uint256 avaxPriceUsd;\n uint256 joePriceUsd;\n uint256 totalAllocChefV2;\n uint256 totalAllocChefV3;\n uint256 joePerSecChefV2;\n uint256 joePerSecChefV3;\n FarmPair[] farmPairsV2;\n FarmPair[] farmPairsV3;\n }\n\n /// @notice Get all data needed for useFarms hook.\n /// @param whitelistedPidsV2 Array of all ids of pools that are whitelisted in chefV2.\n /// @param whitelistedPidsV3 Array of all ids of pools that are whitelisted in chefV3.\n function getAllFarmData(uint256[] calldata whitelistedPidsV2, uint256[] calldata whitelistedPidsV3)\n public\n view\n returns (AllFarmData memory)\n {\n AllFarmData memory allFarmData;\n\n allFarmData.avaxPriceUsd = getAvaxPrice();\n allFarmData.joePriceUsd = getPriceInUsd(joe);\n\n allFarmData.totalAllocChefV2 = IMasterChef(chefv2).totalAllocPoint();\n allFarmData.joePerSecChefV2 = IMasterChef(chefv2).joePerSec();\n\n allFarmData.totalAllocChefV3 = IMasterChef(chefv3).totalAllocPoint();\n allFarmData.joePerSecChefV3 = IMasterChef(chefv3).joePerSec();\n\n allFarmData.farmPairsV2 = getFarmPairs(address(chefv2), whitelistedPidsV2);\n allFarmData.farmPairsV3 = getFarmPairs(address(chefv3), whitelistedPidsV3);\n\n return allFarmData;\n }\n}\n" + }, + "contracts/rewarders/SimpleRewarderPerBlock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"../boringcrypto/BoringOwnable.sol\";\nimport \"../libraries/SafeERC20.sol\";\n\ninterface IRewarder {\n using SafeERC20 for IERC20;\n\n function onJoeReward(address user, uint256 newLpAmount) external;\n\n function pendingTokens(address user) external view returns (uint256 pending);\n\n function rewardToken() external view returns (IERC20);\n}\n\ninterface IMasterChefJoeV2 {\n using SafeERC20 for IERC20;\n\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this poolInfo. SUSHI to distribute per block.\n uint256 lastRewardTimestamp; // Last block timestamp that SUSHI distribution occurs.\n uint256 accJoePerShare; // Accumulated SUSHI per share, times 1e12. See below.\n }\n\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n}\n\n/**\n * This is a sample contract to be used in the MasterChefJoeV2 contract for partners to reward\n * stakers with their native token alongside JOE.\n *\n * It assumes no minting rights, so requires a set amount of YOUR_TOKEN to be transferred to this contract prior.\n * E.g. say you've allocated 100,000 XYZ to the JOE-XYZ farm over 30 days. Then you would need to transfer\n * 100,000 XYZ and set the block reward accordingly so it's fully distributed after 30 days.\n *\n */\ncontract SimpleRewarderPerBlock is IRewarder, BoringOwnable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n IERC20 public immutable override rewardToken;\n IERC20 public immutable lpToken;\n IMasterChefJoeV2 public immutable MC_V2;\n\n /// @notice Info of each MCV2 user.\n /// `amount` LP token amount the user has provided.\n /// `rewardDebt` The amount of YOUR_TOKEN entitled to the user.\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n }\n\n /// @notice Info of each MCV2 poolInfo.\n /// `accTokenPerShare` Amount of YOUR_TOKEN each LP token is worth.\n /// `lastRewardBlock` The last block YOUR_TOKEN was rewarded to the poolInfo.\n struct PoolInfo {\n uint256 accTokenPerShare;\n uint256 lastRewardBlock;\n }\n\n /// @notice Info of the poolInfo.\n PoolInfo public poolInfo;\n /// @notice Info of each user that stakes LP tokens.\n mapping(address => UserInfo) public userInfo;\n\n uint256 public tokenPerBlock;\n uint256 private constant ACC_TOKEN_PRECISION = 1e12;\n\n event OnReward(address indexed user, uint256 amount);\n event RewardRateUpdated(uint256 oldRate, uint256 newRate);\n\n modifier onlyMCV2() {\n require(msg.sender == address(MC_V2), \"onlyMCV2: only MasterChef V2 can call this function\");\n _;\n }\n\n constructor(\n IERC20 _rewardToken,\n IERC20 _lpToken,\n uint256 _tokenPerBlock,\n IMasterChefJoeV2 _MCV2\n ) public {\n require(Address.isContract(address(_rewardToken)), \"constructor: reward token must be a valid contract\");\n require(Address.isContract(address(_lpToken)), \"constructor: LP token must be a valid contract\");\n require(Address.isContract(address(_MCV2)), \"constructor: MasterChefJoeV2 must be a valid contract\");\n\n rewardToken = _rewardToken;\n lpToken = _lpToken;\n tokenPerBlock = _tokenPerBlock;\n MC_V2 = _MCV2;\n poolInfo = PoolInfo({lastRewardBlock: block.number, accTokenPerShare: 0});\n }\n\n /// @notice Update reward variables of the given poolInfo.\n /// @return pool Returns the pool that was updated.\n function updatePool() public returns (PoolInfo memory pool) {\n pool = poolInfo;\n\n if (block.number > pool.lastRewardBlock) {\n uint256 lpSupply = lpToken.balanceOf(address(MC_V2));\n\n if (lpSupply > 0) {\n uint256 blocks = block.number.sub(pool.lastRewardBlock);\n uint256 tokenReward = blocks.mul(tokenPerBlock);\n pool.accTokenPerShare = pool.accTokenPerShare.add((tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply));\n }\n\n pool.lastRewardBlock = block.number;\n poolInfo = pool;\n }\n }\n\n /// @notice Sets the distribution reward rate. This will also update the poolInfo.\n /// @param _tokenPerBlock The number of tokens to distribute per block\n function setRewardRate(uint256 _tokenPerBlock) external onlyOwner {\n updatePool();\n\n uint256 oldRate = tokenPerBlock;\n tokenPerBlock = _tokenPerBlock;\n\n emit RewardRateUpdated(oldRate, _tokenPerBlock);\n }\n\n /// @notice Function called by MasterChefJoeV2 whenever staker claims JOE harvest. Allows staker to also receive a 2nd reward token.\n /// @param _user Address of user\n /// @param _lpAmount Number of LP tokens the user has\n function onJoeReward(address _user, uint256 _lpAmount) external override onlyMCV2 {\n updatePool();\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n uint256 pending;\n // if user had deposited\n if (user.amount > 0) {\n pending = (user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n uint256 balance = rewardToken.balanceOf(address(this));\n if (pending > balance) {\n rewardToken.safeTransfer(_user, balance);\n } else {\n rewardToken.safeTransfer(_user, pending);\n }\n }\n\n user.amount = _lpAmount;\n user.rewardDebt = user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION;\n\n emit OnReward(_user, pending);\n }\n\n /// @notice View function to see pending tokens\n /// @param _user Address of user.\n /// @return pending reward for a given user.\n function pendingTokens(address _user) external view override returns (uint256 pending) {\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n\n uint256 accTokenPerShare = poolInfo.accTokenPerShare;\n uint256 lpSupply = lpToken.balanceOf(address(MC_V2));\n\n if (block.number > poolInfo.lastRewardBlock && lpSupply != 0) {\n uint256 blocks = block.number.sub(poolInfo.lastRewardBlock);\n uint256 tokenReward = blocks.mul(tokenPerBlock);\n accTokenPerShare = accTokenPerShare.add(tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply);\n }\n\n pending = (user.amount.mul(accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n }\n\n /// @notice In case rewarder is stopped before emissions finished, this function allows\n /// withdrawal of remaining tokens.\n function emergencyWithdraw() public onlyOwner {\n rewardToken.safeTransfer(address(msg.sender), rewardToken.balanceOf(address(this)));\n }\n}\n" + }, + "contracts/rewarders/MasterChefRewarderPerSec.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"../libraries/SafeERC20.sol\";\n\ninterface IRewarder {\n using SafeERC20 for IERC20;\n\n function onJoeReward(address user, uint256 newLpAmount) external;\n\n function pendingTokens(address user) external view returns (uint256 pending);\n\n function rewardToken() external view returns (IERC20);\n}\n\ninterface IMasterChef {\n struct PoolInfo {\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n }\n\n function deposit(uint256 _pid, uint256 _amount) external;\n\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n}\n\ninterface IMasterChefJoeV2 {\n using SafeERC20 for IERC20;\n\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this poolInfo. SUSHI to distribute per block.\n uint256 lastRewardTimestamp; // Last block.timestamp that SUSHI distribution occurs.\n uint256 accJoePerShare; // Accumulated SUSHI per share, times 1e12. See below.\n }\n\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n}\n\n/**\n * This is a sample contract to be used in the MasterChefJoeV2 contract for partners to reward\n * stakers with their native token alongside JOE.\n *\n * It assumes the project already has an existing MasterChef-style farm contract.\n * In which case, the init() function is called to deposit a dummy token into one\n * of the MasterChef farms so this contract can accrue rewards from that farm.\n * The contract then transfers the reward token to the user on each call to\n * onJoeReward().\n *\n */\ncontract MasterChefRewarderPerSec is IRewarder, Ownable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n IERC20 public immutable override rewardToken;\n IERC20 public immutable lpToken;\n uint256 public immutable MCV1_pid;\n IMasterChef public immutable MCV1;\n IMasterChefJoeV2 public immutable MCV2;\n\n /// @notice Info of each MCV2 user.\n /// `amount` LP token amount the user has provided.\n /// `rewardDebt` The amount of JOE entitled to the user.\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n }\n\n /// @notice Info of each MCV2 poolInfo.\n /// `accTokenPerShare` Amount of JOE each LP token is worth.\n /// `lastRewardTimestamp` The last time JOE was rewarded to the poolInfo.\n struct PoolInfo {\n uint256 accTokenPerShare;\n uint256 lastRewardTimestamp;\n uint256 allocPoint;\n }\n\n /// @notice Info of the poolInfo.\n PoolInfo public poolInfo;\n /// @notice Info of each user that stakes LP tokens.\n mapping(address => UserInfo) public userInfo;\n\n uint256 public tokenPerSec;\n uint256 private constant ACC_TOKEN_PRECISION = 1e12;\n\n event OnReward(address indexed user, uint256 amount);\n event RewardRateUpdated(uint256 oldRate, uint256 newRate);\n event AllocPointUpdated(uint256 oldAllocPoint, uint256 newAllocPoint);\n\n modifier onlyMCV2() {\n require(msg.sender == address(MCV2), \"onlyMCV2: only MasterChef V2 can call this function\");\n _;\n }\n\n constructor(\n IERC20 _rewardToken,\n IERC20 _lpToken,\n uint256 _tokenPerSec,\n uint256 _allocPoint,\n uint256 _MCV1_pid,\n IMasterChef _MCV1,\n IMasterChefJoeV2 _MCV2\n ) public {\n require(Address.isContract(address(_rewardToken)), \"constructor: reward token must be a valid contract\");\n require(Address.isContract(address(_lpToken)), \"constructor: LP token must be a valid contract\");\n require(Address.isContract(address(_MCV1)), \"constructor: MasterChef must be a valid contract\");\n require(Address.isContract(address(_MCV2)), \"constructor: MasterChefJoeV2 must be a valid contract\");\n\n rewardToken = _rewardToken;\n lpToken = _lpToken;\n tokenPerSec = _tokenPerSec;\n MCV1_pid = _MCV1_pid;\n MCV1 = _MCV1;\n MCV2 = _MCV2;\n poolInfo = PoolInfo({lastRewardTimestamp: block.timestamp, accTokenPerShare: 0, allocPoint: _allocPoint});\n }\n\n /// @notice Deposits a dummy token to a MaterChefV1 farm so that this contract can claim reward tokens.\n /// @param dummyToken The address of the dummy ERC20 token to deposit into MCV1.\n function init(IERC20 dummyToken) external {\n uint256 balance = dummyToken.balanceOf(msg.sender);\n require(balance > 0, \"init: Balance must exceed 0\");\n dummyToken.safeTransferFrom(msg.sender, balance);\n dummyToken.approve(address(MCV1), balance);\n MCV1.deposit(MCV1_pid, balance);\n }\n\n /// @notice Update reward variables of the given poolInfo.\n /// @return pool Returns the pool that was updated.\n function updatePool() public returns (PoolInfo memory pool) {\n pool = poolInfo;\n\n if (block.timestamp > pool.lastRewardTimestamp) {\n uint256 lpSupply = lpToken.balanceOf(address(MCV2));\n\n if (lpSupply > 0) {\n uint256 timeElapsed = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 tokenReward = timeElapsed.mul(tokenPerSec).mul(pool.allocPoint).div(MCV1.totalAllocPoint());\n pool.accTokenPerShare = pool.accTokenPerShare.add((tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply));\n }\n\n pool.lastRewardTimestamp = block.timestamp;\n poolInfo = pool;\n }\n }\n\n /// @notice Sets the distribution reward rate. This will also update the poolInfo.\n /// @param _tokenPerSec The number of tokens to distribute per block\n function setRewardRate(uint256 _tokenPerSec) external onlyOwner {\n updatePool();\n\n uint256 oldRate = tokenPerSec;\n tokenPerSec = _tokenPerSec;\n\n emit RewardRateUpdated(oldRate, _tokenPerSec);\n }\n\n /// @notice Sets the allocation point. THis will also update the poolInfo.\n /// @param _allocPoint The new allocation point of the pool\n function setAllocPoint(uint256 _allocPoint) external onlyOwner {\n updatePool();\n\n uint256 oldAllocPoint = poolInfo.allocPoint;\n poolInfo.allocPoint = _allocPoint;\n\n emit AllocPointUpdated(oldAllocPoint, _allocPoint);\n }\n\n /// @notice Claims reward tokens from MCV1 farm.\n function harvestFromMasterChefV1() public {\n MCV1.deposit(MCV1_pid, 0);\n }\n\n /// @notice Function called by MasterChefJoeV2 whenever staker claims JOE harvest. Allows staker to also receive a 2nd reward token.\n /// @param _user Address of user\n /// @param _lpAmount Number of LP tokens the user has\n function onJoeReward(address _user, uint256 _lpAmount) external override onlyMCV2 {\n updatePool();\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n uint256 pendingBal;\n // if user had deposited\n if (user.amount > 0) {\n harvestFromMasterChefV1();\n pendingBal = (user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n uint256 rewardBal = rewardToken.balanceOf(address(this));\n if (pendingBal > rewardBal) {\n rewardToken.safeTransfer(_user, rewardBal);\n } else {\n rewardToken.safeTransfer(_user, pendingBal);\n }\n }\n\n user.amount = _lpAmount;\n user.rewardDebt = user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION;\n\n emit OnReward(_user, pendingBal);\n }\n\n /// @notice View function to see pending tokens\n /// @param _user Address of user.\n /// @return pending reward for a given user.\n function pendingTokens(address _user) external view override returns (uint256 pending) {\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n\n uint256 accTokenPerShare = pool.accTokenPerShare;\n uint256 lpSupply = lpToken.balanceOf(address(MCV2));\n\n if (block.timestamp > pool.lastRewardTimestamp && lpSupply != 0) {\n uint256 blocks = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 tokenReward = blocks.mul(tokenPerSec).mul(pool.allocPoint).div(MCV1.totalAllocPoint());\n accTokenPerShare = accTokenPerShare.add(tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply);\n }\n\n pending = (user.amount.mul(accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n }\n}\n" + }, + "contracts/rewarders/MasterChefRewarderPerBlock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"../libraries/SafeERC20.sol\";\nimport \"../interfaces/IRewarder.sol\";\n\n\ninterface IMasterChef {\n struct PoolInfo {\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n }\n\n function deposit(uint256 _pid, uint256 _amount) external;\n\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n}\n\ninterface IMasterChefJoeV2 {\n using SafeERC20 for IERC20;\n\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this poolInfo. SUSHI to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that SUSHI distribution occurs.\n uint256 accJoePerShare; // Accumulated SUSHI per share, times 1e12. See below.\n }\n\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n}\n\n/**\n * This is a sample contract to be used in the MasterChefJoeV2 contract for partners to reward\n * stakers with their native token alongside JOE.\n *\n * It assumes the project already has an existing MasterChef-style farm contract.\n * In which case, the init() function is called to deposit a dummy token into one\n * of the MasterChef farms so this contract can accrue rewards from that farm.\n * The contract then transfers the reward token to the user on each call to\n * onJoeReward().\n *\n */\ncontract MasterChefRewarderPerBlock is IRewarder, Ownable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n IERC20 public immutable override rewardToken;\n IERC20 public immutable lpToken;\n uint256 public immutable MCV1_pid;\n IMasterChef public immutable MCV1;\n IMasterChefJoeV2 public immutable MCV2;\n\n /// @notice Info of each MCV2 user.\n /// `amount` LP token amount the user has provided.\n /// `rewardDebt` The amount of JOE entitled to the user.\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n }\n\n /// @notice Info of each MCV2 poolInfo.\n /// `accTokenPerShare` Amount of JOE each LP token is worth.\n /// `lastRewardBlock` The last block JOE was rewarded to the poolInfo.\n struct PoolInfo {\n uint256 accTokenPerShare;\n uint256 lastRewardBlock;\n uint256 allocPoint;\n }\n\n /// @notice Info of the poolInfo.\n PoolInfo public poolInfo;\n /// @notice Info of each user that stakes LP tokens.\n mapping(address => UserInfo) public userInfo;\n\n uint256 public tokenPerBlock;\n uint256 private constant ACC_TOKEN_PRECISION = 1e12;\n\n event OnReward(address indexed user, uint256 amount);\n event RewardRateUpdated(uint256 oldRate, uint256 newRate);\n event AllocPointUpdated(uint256 oldAllocPoint, uint256 newAllocPoint);\n\n modifier onlyMCV2() {\n require(msg.sender == address(MCV2), \"onlyMCV2: only MasterChef V2 can call this function\");\n _;\n }\n\n constructor(\n IERC20 _rewardToken,\n IERC20 _lpToken,\n uint256 _tokenPerBlock,\n uint256 _allocPoint,\n uint256 _MCV1_pid,\n IMasterChef _MCV1,\n IMasterChefJoeV2 _MCV2\n ) public {\n require(Address.isContract(address(_rewardToken)), \"constructor: reward token must be a valid contract\");\n require(Address.isContract(address(_lpToken)), \"constructor: LP token must be a valid contract\");\n require(Address.isContract(address(_MCV1)), \"constructor: MasterChef must be a valid contract\");\n require(Address.isContract(address(_MCV2)), \"constructor: MasterChefJoeV2 must be a valid contract\");\n\n rewardToken = _rewardToken;\n lpToken = _lpToken;\n tokenPerBlock = _tokenPerBlock;\n MCV1_pid = _MCV1_pid;\n MCV1 = _MCV1;\n MCV2 = _MCV2;\n poolInfo = PoolInfo({lastRewardBlock: block.number, accTokenPerShare: 0, allocPoint: _allocPoint});\n }\n\n /// @notice Deposits a dummy token to a MaterChefV1 farm so that this contract can claim reward tokens.\n /// @param dummyToken The address of the dummy ERC20 token to deposit into MCV1.\n function init(IERC20 dummyToken) external {\n uint256 balance = dummyToken.balanceOf(msg.sender);\n require(balance > 0, \"init: Balance must exceed 0\");\n dummyToken.safeTransferFrom(msg.sender, balance);\n dummyToken.approve(address(MCV1), balance);\n MCV1.deposit(MCV1_pid, balance);\n }\n\n /// @notice Update reward variables of the given poolInfo.\n /// @return pool Returns the pool that was updated.\n function updatePool() public returns (PoolInfo memory pool) {\n pool = poolInfo;\n\n if (block.number > pool.lastRewardBlock) {\n uint256 lpSupply = lpToken.balanceOf(address(MCV2));\n\n if (lpSupply > 0) {\n uint256 blocks = block.number.sub(pool.lastRewardBlock);\n uint256 tokenReward = blocks.mul(tokenPerBlock).mul(pool.allocPoint).div(MCV1.totalAllocPoint());\n pool.accTokenPerShare = pool.accTokenPerShare.add((tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply));\n }\n\n pool.lastRewardBlock = block.number;\n poolInfo = pool;\n }\n }\n\n /// @notice Sets the distribution reward rate. This will also update the poolInfo.\n /// @param _tokenPerBlock The number of tokens to distribute per block\n function setRewardRate(uint256 _tokenPerBlock) external onlyOwner {\n updatePool();\n\n uint256 oldRate = tokenPerBlock;\n tokenPerBlock = _tokenPerBlock;\n\n emit RewardRateUpdated(oldRate, _tokenPerBlock);\n }\n\n /// @notice Sets the allocation point. THis will also update the poolInfo.\n /// @param _allocPoint The new allocation point of the pool\n function setAllocPoint(uint256 _allocPoint) external onlyOwner {\n updatePool();\n\n uint256 oldAllocPoint = poolInfo.allocPoint;\n poolInfo.allocPoint = _allocPoint;\n\n emit AllocPointUpdated(oldAllocPoint, _allocPoint);\n }\n\n /// @notice Claims reward tokens from MCV1 farm.\n function harvestFromMasterChefV1() public {\n MCV1.deposit(MCV1_pid, 0);\n }\n\n /// @notice Function called by MasterChefJoeV2 whenever staker claims JOE harvest. Allows staker to also receive a 2nd reward token.\n /// @param _user Address of user\n /// @param _lpAmount Number of LP tokens the user has\n function onJoeReward(address _user, uint256 _lpAmount) external override onlyMCV2 {\n updatePool();\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n uint256 pendingBal;\n // if user had deposited\n if (user.amount > 0) {\n harvestFromMasterChefV1();\n pendingBal = (user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n uint256 rewardBal = rewardToken.balanceOf(address(this));\n if (pendingBal > rewardBal) {\n rewardToken.safeTransfer(_user, rewardBal);\n } else {\n rewardToken.safeTransfer(_user, pendingBal);\n }\n }\n\n user.amount = _lpAmount;\n user.rewardDebt = user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION;\n\n emit OnReward(_user, pendingBal);\n }\n\n /// @notice View function to see pending tokens\n /// @param _user Address of user.\n /// @return pending reward for a given user.\n function pendingTokens(address _user) external view override returns (uint256 pending) {\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n\n uint256 accTokenPerShare = pool.accTokenPerShare;\n uint256 lpSupply = lpToken.balanceOf(address(MCV2));\n\n if (block.number > pool.lastRewardBlock && lpSupply != 0) {\n uint256 blocks = block.number.sub(pool.lastRewardBlock);\n uint256 tokenReward = blocks.mul(tokenPerBlock).mul(pool.allocPoint).div(MCV1.totalAllocPoint());\n accTokenPerShare = accTokenPerShare.add(tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply);\n }\n\n pending = (user.amount.mul(accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n }\n}\n" + }, + "contracts/MasterChefJoeV3.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/EnumerableSet.sol\";\nimport \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\nimport \"./interfaces/IERC20.sol\";\n\ninterface IMasterChef {\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\n }\n\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function joePerSec() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n\n function devPercent() external view returns (uint256);\n\n function treasuryPercent() external view returns (uint256);\n\n function investorPercent() external view returns (uint256);\n}\n\ninterface IRewarder {\n function onJoeReward(address user, uint256 newLpAmount) external;\n\n function pendingTokens(address user) external view returns (uint256 pending);\n\n function rewardToken() external view returns (IERC20);\n}\n\nlibrary BoringERC20 {\n bytes4 private constant SIG_SYMBOL = 0x95d89b41; // symbol()\n bytes4 private constant SIG_NAME = 0x06fdde03; // name()\n bytes4 private constant SIG_DECIMALS = 0x313ce567; // decimals()\n bytes4 private constant SIG_TRANSFER = 0xa9059cbb; // transfer(address,uint256)\n bytes4 private constant SIG_TRANSFER_FROM = 0x23b872dd; // transferFrom(address,address,uint256)\n\n function returnDataToString(bytes memory data) internal pure returns (string memory) {\n if (data.length >= 64) {\n return abi.decode(data, (string));\n } else if (data.length == 32) {\n uint8 i = 0;\n while (i < 32 && data[i] != 0) {\n i++;\n }\n bytes memory bytesArray = new bytes(i);\n for (i = 0; i < 32 && data[i] != 0; i++) {\n bytesArray[i] = data[i];\n }\n return string(bytesArray);\n } else {\n return \"???\";\n }\n }\n\n /// @notice Provides a safe ERC20.symbol version which returns '???' as fallback string.\n /// @param token The address of the ERC-20 token contract.\n /// @return (string) Token symbol.\n function safeSymbol(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_SYMBOL));\n return success ? returnDataToString(data) : \"???\";\n }\n\n /// @notice Provides a safe ERC20.name version which returns '???' as fallback string.\n /// @param token The address of the ERC-20 token contract.\n /// @return (string) Token name.\n function safeName(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_NAME));\n return success ? returnDataToString(data) : \"???\";\n }\n\n /// @notice Provides a safe ERC20.decimals version which returns '18' as fallback value.\n /// @param token The address of the ERC-20 token contract.\n /// @return (uint8) Token decimals.\n function safeDecimals(IERC20 token) internal view returns (uint8) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_DECIMALS));\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\n }\n\n /// @notice Provides a safe ERC20.transfer version for different ERC-20 implementations.\n /// Reverts on a failed transfer.\n /// @param token The address of the ERC-20 token.\n /// @param to Transfer tokens to.\n /// @param amount The token amount.\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(SIG_TRANSFER, to, amount));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"BoringERC20: Transfer failed\");\n }\n\n /// @notice Provides a safe ERC20.transferFrom version for different ERC-20 implementations.\n /// Reverts on a failed transfer.\n /// @param token The address of the ERC-20 token.\n /// @param from Transfer tokens from.\n /// @param to Transfer tokens to.\n /// @param amount The token amount.\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(\n abi.encodeWithSelector(SIG_TRANSFER_FROM, from, to, amount)\n );\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"BoringERC20: TransferFrom failed\");\n }\n}\n\n/// @notice The (older) MasterChefJoeV2 contract gives out a constant number of JOE tokens per block.\n/// It is the only address with minting rights for JOE.\n/// The idea for this MasterChefJoeV3 (MCJV3) contract is therefore to be the owner of a dummy token\n/// that is deposited into the MasterChefJoeV2 (MCJV2) contract.\n/// The allocation point for this pool on MCJV3 is the total allocation point for all pools that receive double incentives.\ncontract MasterChefJoeV3 is Ownable, ReentrancyGuard {\n using SafeMath for uint256;\n using BoringERC20 for IERC20;\n using EnumerableSet for EnumerableSet.AddressSet;\n\n /// @notice Info of each MCJV3 user.\n /// `amount` LP token amount the user has provided.\n /// `rewardDebt` The amount of JOE entitled to the user.\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n }\n\n /// @notice Info of each MCJV3 pool.\n /// `allocPoint` The amount of allocation points assigned to the pool.\n /// Also known as the amount of JOE to distribute per block.\n struct PoolInfo {\n IERC20 lpToken;\n uint256 accJoePerShare;\n uint256 lastRewardTimestamp;\n uint256 allocPoint;\n IRewarder rewarder;\n }\n\n /// @notice Address of MCJV2 contract.\n IMasterChef public immutable MASTER_CHEF_V2;\n /// @notice Address of JOE contract.\n IERC20 public immutable JOE;\n /// @notice The index of MCJV3 master pool in MCJV2\n uint256 public immutable MASTER_PID;\n /// @notice Info of each MCJV3 pool.\n PoolInfo[] public poolInfo;\n // Set of all LP tokens that have been added as pools\n EnumerableSet.AddressSet private lpTokens;\n /// @notice Info of each user that stakes LP tokens.\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n /// @dev Total allocation points. Must be the sum of all allocation points in all pools.\n uint256 public totalAllocPoint;\n uint256 private constant ACC_TOKEN_PRECISION = 1e18;\n\n event Add(uint256 indexed pid, uint256 allocPoint, IERC20 indexed lpToken, IRewarder indexed rewarder);\n event Set(uint256 indexed pid, uint256 allocPoint, IRewarder indexed rewarder, bool overwrite);\n event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\n event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event UpdatePool(uint256 indexed pid, uint256 lastRewardTimestamp, uint256 lpSupply, uint256 accJoePerShare);\n event Harvest(address indexed user, uint256 indexed pid, uint256 amount);\n event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event Init();\n\n /// @param _MASTER_CHEF_V2 The JoeSwap MCJV2 contract address.\n /// @param _joe The JOE token contract address.\n /// @param _MASTER_PID The pool ID of the dummy token on the base MCJV2 contract.\n constructor(\n IMasterChef _MASTER_CHEF_V2,\n IERC20 _joe,\n uint256 _MASTER_PID\n ) public {\n MASTER_CHEF_V2 = _MASTER_CHEF_V2;\n JOE = _joe;\n MASTER_PID = _MASTER_PID;\n }\n\n /// @notice Deposits a dummy token to `MASTER_CHEF_V2` MCJV2. This is required because MCJV2 holds the minting rights for JOE.\n /// Any balance of transaction sender in `dummyToken` is transferred.\n /// The allocation point for the pool on MCJV2 is the total allocation point for all pools that receive double incentives.\n /// @param dummyToken The address of the ERC-20 token to deposit into MCJV2.\n function init(IERC20 dummyToken) external onlyOwner {\n uint256 balance = dummyToken.balanceOf(msg.sender);\n require(balance != 0, \"MasterChefV2: Balance must exceed 0\");\n dummyToken.safeTransferFrom(msg.sender, address(this), balance);\n dummyToken.approve(address(MASTER_CHEF_V2), balance);\n MASTER_CHEF_V2.deposit(MASTER_PID, balance);\n emit Init();\n }\n\n /// @notice Returns the number of MCJV3 pools.\n function poolLength() external view returns (uint256 pools) {\n pools = poolInfo.length;\n }\n\n /// @notice Add a new LP to the pool. Can only be called by the owner.\n /// DO NOT add the same LP token more than once. Rewards will be messed up if you do.\n /// @param allocPoint AP of the new pool.\n /// @param _lpToken Address of the LP ERC-20 token.\n /// @param _rewarder Address of the rewarder delegate.\n function add(\n uint256 allocPoint,\n IERC20 _lpToken,\n IRewarder _rewarder\n ) external onlyOwner {\n require(!lpTokens.contains(address(_lpToken)), \"add: LP already added\");\n // Sanity check to ensure _lpToken is an ERC20 token\n _lpToken.balanceOf(address(this));\n // Sanity check if we add a rewarder\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(address(0), 0);\n }\n\n uint256 lastRewardTimestamp = block.timestamp;\n totalAllocPoint = totalAllocPoint.add(allocPoint);\n\n poolInfo.push(\n PoolInfo({\n lpToken: _lpToken,\n allocPoint: allocPoint,\n lastRewardTimestamp: lastRewardTimestamp,\n accJoePerShare: 0,\n rewarder: _rewarder\n })\n );\n lpTokens.add(address(_lpToken));\n emit Add(poolInfo.length.sub(1), allocPoint, _lpToken, _rewarder);\n }\n\n /// @notice Update the given pool's JOE allocation point and `IRewarder` contract. Can only be called by the owner.\n /// @param _pid The index of the pool. See `poolInfo`.\n /// @param _allocPoint New AP of the pool.\n /// @param _rewarder Address of the rewarder delegate.\n /// @param overwrite True if _rewarder should be `set`. Otherwise `_rewarder` is ignored.\n function set(\n uint256 _pid,\n uint256 _allocPoint,\n IRewarder _rewarder,\n bool overwrite\n ) external onlyOwner {\n PoolInfo memory pool = poolInfo[_pid];\n totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);\n pool.allocPoint = _allocPoint;\n if (overwrite) {\n _rewarder.onJoeReward(address(0), 0); // sanity check\n pool.rewarder = _rewarder;\n }\n poolInfo[_pid] = pool;\n emit Set(_pid, _allocPoint, overwrite ? _rewarder : pool.rewarder, overwrite);\n }\n\n /// @notice View function to see pending JOE on frontend.\n /// @param _pid The index of the pool. See `poolInfo`.\n /// @param _user Address of user.\n /// @return pendingJoe JOE reward for a given user.\n // bonusTokenAddress The address of the bonus reward.\n // bonusTokenSymbol The symbol of the bonus token.\n // pendingBonusToken The amount of bonus rewards pending.\n function pendingTokens(uint256 _pid, address _user)\n external\n view\n returns (\n uint256 pendingJoe,\n address bonusTokenAddress,\n string memory bonusTokenSymbol,\n uint256 pendingBonusToken\n )\n {\n PoolInfo memory pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_user];\n uint256 accJoePerShare = pool.accJoePerShare;\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (block.timestamp > pool.lastRewardTimestamp && lpSupply != 0) {\n uint256 secondsElapsed = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 joeReward = secondsElapsed.mul(joePerSec()).mul(pool.allocPoint).div(totalAllocPoint);\n accJoePerShare = accJoePerShare.add(joeReward.mul(ACC_TOKEN_PRECISION).div(lpSupply));\n }\n pendingJoe = user.amount.mul(accJoePerShare).div(ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n\n // If it's a double reward farm, we return info about the bonus token\n if (address(pool.rewarder) != address(0)) {\n bonusTokenAddress = address(pool.rewarder.rewardToken());\n bonusTokenSymbol = IERC20(pool.rewarder.rewardToken()).safeSymbol();\n pendingBonusToken = pool.rewarder.pendingTokens(_user);\n }\n }\n\n /// @notice Update reward variables for all pools. Be careful of gas spending!\n /// @param pids Pool IDs of all to be updated. Make sure to update all active pools.\n function massUpdatePools(uint256[] calldata pids) external {\n uint256 len = pids.length;\n for (uint256 i = 0; i < len; ++i) {\n updatePool(pids[i]);\n }\n }\n\n /// @notice Calculates and returns the `amount` of JOE per block.\n function joePerSec() public view returns (uint256 amount) {\n uint256 total = 1000;\n uint256 lpPercent = total.sub(MASTER_CHEF_V2.devPercent()).sub(MASTER_CHEF_V2.treasuryPercent()).sub(\n MASTER_CHEF_V2.investorPercent()\n );\n uint256 lpShare = MASTER_CHEF_V2.joePerSec().mul(lpPercent).div(total);\n amount = lpShare.mul(MASTER_CHEF_V2.poolInfo(MASTER_PID).allocPoint).div(MASTER_CHEF_V2.totalAllocPoint());\n }\n\n /// @notice Update reward variables of the given pool.\n /// @param pid The index of the pool. See `poolInfo`.\n function updatePool(uint256 pid) public {\n PoolInfo memory pool = poolInfo[pid];\n if (block.timestamp > pool.lastRewardTimestamp) {\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (lpSupply > 0) {\n uint256 secondsElapsed = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 joeReward = secondsElapsed.mul(joePerSec()).mul(pool.allocPoint).div(totalAllocPoint);\n pool.accJoePerShare = pool.accJoePerShare.add((joeReward.mul(ACC_TOKEN_PRECISION).div(lpSupply)));\n }\n pool.lastRewardTimestamp = block.timestamp;\n poolInfo[pid] = pool;\n emit UpdatePool(pid, pool.lastRewardTimestamp, lpSupply, pool.accJoePerShare);\n }\n }\n\n /// @notice Deposit LP tokens to MCJV3 for JOE allocation.\n /// @param pid The index of the pool. See `poolInfo`.\n /// @param amount LP token amount to deposit.\n function deposit(uint256 pid, uint256 amount) external nonReentrant {\n harvestFromMasterChef();\n updatePool(pid);\n PoolInfo memory pool = poolInfo[pid];\n UserInfo storage user = userInfo[pid][msg.sender];\n\n if (user.amount > 0) {\n // Harvest JOE\n uint256 pending = user.amount.mul(pool.accJoePerShare).div(ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n JOE.safeTransfer(msg.sender, pending);\n emit Harvest(msg.sender, pid, pending);\n }\n\n uint256 balanceBefore = pool.lpToken.balanceOf(address(this));\n pool.lpToken.safeTransferFrom(msg.sender, address(this), amount);\n uint256 receivedAmount = pool.lpToken.balanceOf(address(this)).sub(balanceBefore);\n\n // Effects\n user.amount = user.amount.add(receivedAmount);\n user.rewardDebt = user.amount.mul(pool.accJoePerShare).div(ACC_TOKEN_PRECISION);\n\n // Interactions\n IRewarder _rewarder = pool.rewarder;\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(msg.sender, user.amount);\n }\n\n emit Deposit(msg.sender, pid, receivedAmount);\n }\n\n /// @notice Withdraw LP tokens from MCJV3.\n /// @param pid The index of the pool. See `poolInfo`.\n /// @param amount LP token amount to withdraw.\n function withdraw(uint256 pid, uint256 amount) external nonReentrant {\n harvestFromMasterChef();\n updatePool(pid);\n PoolInfo memory pool = poolInfo[pid];\n UserInfo storage user = userInfo[pid][msg.sender];\n\n if (user.amount > 0) {\n // Harvest JOE\n uint256 pending = user.amount.mul(pool.accJoePerShare).div(ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n JOE.safeTransfer(msg.sender, pending);\n emit Harvest(msg.sender, pid, pending);\n }\n\n // Effects\n user.amount = user.amount.sub(amount);\n user.rewardDebt = user.amount.mul(pool.accJoePerShare).div(ACC_TOKEN_PRECISION);\n\n // Interactions\n IRewarder _rewarder = pool.rewarder;\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(msg.sender, user.amount);\n }\n\n pool.lpToken.safeTransfer(msg.sender, amount);\n\n emit Withdraw(msg.sender, pid, amount);\n }\n\n /// @notice Harvests JOE from `MASTER_CHEF_V2` MCJV2 and pool `MASTER_PID` to this MCJV3 contract.\n function harvestFromMasterChef() public {\n MASTER_CHEF_V2.deposit(MASTER_PID, 0);\n }\n\n /// @notice Withdraw without caring about rewards. EMERGENCY ONLY.\n /// @param pid The index of the pool. See `poolInfo`.\n function emergencyWithdraw(uint256 pid) external nonReentrant {\n PoolInfo memory pool = poolInfo[pid];\n UserInfo storage user = userInfo[pid][msg.sender];\n uint256 amount = user.amount;\n user.amount = 0;\n user.rewardDebt = 0;\n\n IRewarder _rewarder = pool.rewarder;\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(msg.sender, 0);\n }\n\n // Note: transfer can fail or succeed if `amount` is zero.\n pool.lpToken.safeTransfer(msg.sender, amount);\n emit EmergencyWithdraw(msg.sender, pid, amount);\n }\n}\n" + }, + "contracts/interfaces/IPair.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"./IERC20.sol\";\n\ninterface IPair is IERC20 {\n function token0() external view returns (address);\n\n function token1() external view returns (address);\n\n function getReserves()\n external\n view\n returns (\n uint112,\n uint112,\n uint32\n );\n}\n" + }, + "contracts/libraries/BoringPair.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\nimport \"../interfaces/IPair.sol\";\nimport \"../interfaces/IFactory.sol\";\n\nlibrary BoringPair {\n function factory(IPair pair) internal view returns (IFactory) {\n (bool success, bytes memory data) = address(pair).staticcall(abi.encodeWithSelector(0xc45a0155));\n return success && data.length == 32 ? abi.decode(data, (IFactory)) : IFactory(0);\n }\n}\n" + }, + "contracts/interfaces/IFactory.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\ninterface IFactory {\n function allPairsLength() external view returns (uint256);\n\n function allPairs(uint256 i) external view returns (address);\n\n function getPair(address token0, address token1) external view returns (address);\n\n function feeTo() external view returns (address);\n\n function feeToSetter() external view returns (address);\n}\n" + }, + "contracts/boringcrypto/BoringCryptoTokenScanner.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n/**\n *Submitted for verification at Etherscan.io on 2020-09-18\n */\n\npragma solidity ^0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"../interfaces/IFactory.sol\";\n\ninterface IERC20 {\n function name() external view returns (string memory);\n\n function symbol() external view returns (string memory);\n\n function decimals() external view returns (uint256);\n\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n\n function transfer(address recipient, uint256 amount) external returns (bool);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 amount) external returns (bool);\n\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) external returns (bool);\n\n function owner() external view returns (address);\n\n event Transfer(address indexed from, address indexed to, uint256 value);\n event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n\nlibrary BoringERC20 {\n function returnDataToString(bytes memory data) internal pure returns (string memory) {\n if (data.length >= 64) {\n return abi.decode(data, (string));\n } else if (data.length == 32) {\n uint8 i = 0;\n while (i < 32 && data[i] != 0) {\n i++;\n }\n bytes memory bytesArray = new bytes(i);\n for (i = 0; i < 32 && data[i] != 0; i++) {\n bytesArray[i] = data[i];\n }\n return string(bytesArray);\n } else {\n return \"???\";\n }\n }\n\n function symbol(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x95d89b41));\n return success ? returnDataToString(data) : \"???\";\n }\n\n function name(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x06fdde03));\n return success ? returnDataToString(data) : \"???\";\n }\n\n function decimals(IERC20 token) internal view returns (uint8) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x313ce567));\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\n }\n\n function DOMAIN_SEPARATOR(IERC20 token) internal view returns (bytes32) {\n (bool success, bytes memory data) = address(token).staticcall{gas: 10000}(abi.encodeWithSelector(0x3644e515));\n return success && data.length == 32 ? abi.decode(data, (bytes32)) : bytes32(0);\n }\n\n function nonces(IERC20 token, address owner) internal view returns (uint256) {\n (bool success, bytes memory data) = address(token).staticcall{gas: 5000}(\n abi.encodeWithSelector(0x7ecebe00, owner)\n );\n // Use max uint256 to signal failure to retrieve nonce (probably not supported)\n return success && data.length == 32 ? abi.decode(data, (uint256)) : uint256(-1);\n }\n}\n\ninterface IMasterChef {\n function BONUS_MULTIPLIER() external view returns (uint256);\n\n function devaddr() external view returns (address);\n\n function owner() external view returns (address);\n\n function startTimestamp() external view returns (uint256);\n\n function joe() external view returns (address);\n\n function joePerSec() external view returns (uint256);\n\n function totalAllocPoint() external view returns (uint256);\n\n function poolLength() external view returns (uint256);\n\n function poolInfo(uint256 nr)\n external\n view\n returns (\n address,\n uint256,\n uint256,\n uint256\n );\n\n function userInfo(uint256 nr, address who) external view returns (uint256, uint256);\n\n function pendingTokens(uint256 pid, address who)\n external\n view\n returns (\n uint256,\n address,\n string memory,\n uint256\n );\n}\n\ninterface IPair is IERC20 {\n function token0() external view returns (address);\n\n function token1() external view returns (address);\n\n function getReserves()\n external\n view\n returns (\n uint112,\n uint112,\n uint32\n );\n}\n\ncontract BoringCryptoTokenScanner {\n using SafeMath for uint256;\n\n struct Balance {\n address token;\n uint256 balance;\n }\n\n struct BalanceFull {\n address token;\n uint256 balance;\n uint256 rate;\n }\n\n struct TokenInfo {\n address token;\n uint256 decimals;\n string name;\n string symbol;\n }\n\n function getTokenInfo(address[] calldata addresses) public view returns (TokenInfo[] memory) {\n TokenInfo[] memory infos = new TokenInfo[](addresses.length);\n\n for (uint256 i = 0; i < addresses.length; i++) {\n IERC20 token = IERC20(addresses[i]);\n infos[i].token = address(token);\n\n infos[i].name = token.name();\n infos[i].symbol = token.symbol();\n infos[i].decimals = token.decimals();\n }\n\n return infos;\n }\n\n function findBalances(address who, address[] calldata addresses) public view returns (Balance[] memory) {\n uint256 balanceCount;\n\n for (uint256 i = 0; i < addresses.length; i++) {\n if (IERC20(addresses[i]).balanceOf(who) > 0) {\n balanceCount++;\n }\n }\n\n Balance[] memory balances = new Balance[](balanceCount);\n\n balanceCount = 0;\n for (uint256 i = 0; i < addresses.length; i++) {\n IERC20 token = IERC20(addresses[i]);\n uint256 balance = token.balanceOf(who);\n if (balance > 0) {\n balances[balanceCount].token = address(token);\n balances[balanceCount].balance = token.balanceOf(who);\n balanceCount++;\n }\n }\n\n return balances;\n }\n\n function getBalances(\n address who,\n address[] calldata addresses,\n IFactory factory,\n address currency\n ) public view returns (BalanceFull[] memory) {\n BalanceFull[] memory balances = new BalanceFull[](addresses.length);\n\n for (uint256 i = 0; i < addresses.length; i++) {\n IERC20 token = IERC20(addresses[i]);\n balances[i].token = address(token);\n balances[i].balance = token.balanceOf(who);\n\n IPair pair = IPair(factory.getPair(addresses[i], currency));\n if (address(pair) != address(0)) {\n uint256 reserveCurrency;\n uint256 reserveToken;\n if (pair.token0() == currency) {\n (reserveCurrency, reserveToken, ) = pair.getReserves();\n } else {\n (reserveToken, reserveCurrency, ) = pair.getReserves();\n }\n balances[i].rate = (reserveToken * 1e18) / reserveCurrency;\n }\n }\n\n return balances;\n }\n\n struct Factory {\n IFactory factory;\n uint256 allPairsLength;\n address feeTo;\n address feeToSetter;\n }\n\n function getFactoryInfo(IFactory[] calldata addresses) public view returns (Factory[] memory) {\n Factory[] memory factories = new Factory[](addresses.length);\n\n for (uint256 i = 0; i < addresses.length; i++) {\n IFactory factory = addresses[i];\n factories[i].factory = factory;\n\n factories[i].allPairsLength = factory.allPairsLength();\n factories[i].feeTo = factory.feeTo();\n factories[i].feeToSetter = factory.feeToSetter();\n }\n\n return factories;\n }\n\n struct Pair {\n address token;\n address token0;\n address token1;\n }\n\n function getPairs(\n IFactory factory,\n uint256 fromID,\n uint256 toID\n ) public view returns (Pair[] memory) {\n if (toID == 0) {\n toID = factory.allPairsLength();\n }\n\n Pair[] memory pairs = new Pair[](toID - fromID);\n\n for (uint256 id = fromID; id < toID; id++) {\n address token = factory.allPairs(id);\n uint256 i = id - fromID;\n pairs[i].token = token;\n pairs[i].token0 = IPair(token).token0();\n pairs[i].token1 = IPair(token).token1();\n }\n return pairs;\n }\n\n function findPairs(\n address who,\n IFactory factory,\n uint256 fromID,\n uint256 toID\n ) public view returns (Pair[] memory) {\n if (toID == 0) {\n toID = factory.allPairsLength();\n }\n\n uint256 pairCount;\n\n for (uint256 id = fromID; id < toID; id++) {\n address token = factory.allPairs(id);\n if (IERC20(token).balanceOf(who) > 0) {\n pairCount++;\n }\n }\n\n Pair[] memory pairs = new Pair[](pairCount);\n\n pairCount = 0;\n for (uint256 id = fromID; id < toID; id++) {\n address token = factory.allPairs(id);\n uint256 balance = IERC20(token).balanceOf(who);\n if (balance > 0) {\n pairs[pairCount].token = token;\n pairs[pairCount].token0 = IPair(token).token0();\n pairs[pairCount].token1 = IPair(token).token1();\n pairCount++;\n }\n }\n\n return pairs;\n }\n\n struct PairFull {\n address token;\n address token0;\n address token1;\n uint256 reserve0;\n uint256 reserve1;\n uint256 totalSupply;\n uint256 balance;\n }\n\n function getPairsFull(address who, address[] calldata addresses) public view returns (PairFull[] memory) {\n PairFull[] memory pairs = new PairFull[](addresses.length);\n for (uint256 i = 0; i < addresses.length; i++) {\n address token = addresses[i];\n pairs[i].token = token;\n pairs[i].token0 = IPair(token).token0();\n pairs[i].token1 = IPair(token).token1();\n (uint256 reserve0, uint256 reserve1, ) = IPair(token).getReserves();\n pairs[i].reserve0 = reserve0;\n pairs[i].reserve1 = reserve1;\n pairs[i].balance = IERC20(token).balanceOf(who);\n }\n return pairs;\n }\n}\n" + }, + "contracts/boringcrypto/BoringCryptoDashboardV2.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n/**\n *Submitted for verification at Etherscan.io on 2020-10-09\n */\n\npragma solidity ^0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"../interfaces/IFactory.sol\";\n\ninterface IERC20 {\n function name() external view returns (string memory);\n\n function symbol() external view returns (string memory);\n\n function decimals() external view returns (uint256);\n\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n\n function transfer(address recipient, uint256 amount) external returns (bool);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 amount) external returns (bool);\n\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) external returns (bool);\n\n function owner() external view returns (address);\n\n event Transfer(address indexed from, address indexed to, uint256 value);\n event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n\nlibrary BoringERC20 {\n function returnDataToString(bytes memory data) internal pure returns (string memory) {\n if (data.length >= 64) {\n return abi.decode(data, (string));\n } else if (data.length == 32) {\n uint8 i = 0;\n while (i < 32 && data[i] != 0) {\n i++;\n }\n bytes memory bytesArray = new bytes(i);\n for (i = 0; i < 32 && data[i] != 0; i++) {\n bytesArray[i] = data[i];\n }\n return string(bytesArray);\n } else {\n return \"???\";\n }\n }\n\n function symbol(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x95d89b41));\n return success ? returnDataToString(data) : \"???\";\n }\n\n function name(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x06fdde03));\n return success ? returnDataToString(data) : \"???\";\n }\n\n function decimals(IERC20 token) internal view returns (uint8) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x313ce567));\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\n }\n\n function DOMAIN_SEPARATOR(IERC20 token) internal view returns (bytes32) {\n (bool success, bytes memory data) = address(token).staticcall{gas: 10000}(abi.encodeWithSelector(0x3644e515));\n return success && data.length == 32 ? abi.decode(data, (bytes32)) : bytes32(0);\n }\n\n function nonces(IERC20 token, address owner) internal view returns (uint256) {\n (bool success, bytes memory data) = address(token).staticcall{gas: 5000}(\n abi.encodeWithSelector(0x7ecebe00, owner)\n );\n // Use max uint256 to signal failure to retrieve nonce (probably not supported)\n return success && data.length == 32 ? abi.decode(data, (uint256)) : uint256(-1);\n }\n}\n\ninterface IMasterChef {\n function BONUS_MULTIPLIER() external view returns (uint256);\n\n function devaddr() external view returns (address);\n\n function owner() external view returns (address);\n\n function startTimestamp() external view returns (uint256);\n\n function joe() external view returns (address);\n\n function joePerSec() external view returns (uint256);\n\n function totalAllocPoint() external view returns (uint256);\n\n function poolLength() external view returns (uint256);\n\n function poolInfo(uint256 nr)\n external\n view\n returns (\n address,\n uint256,\n uint256,\n uint256\n );\n\n function userInfo(uint256 nr, address who) external view returns (uint256, uint256);\n\n function pendingTokens(uint256 pid, address who)\n external\n view\n returns (\n uint256,\n address,\n string memory,\n uint256\n );\n}\n\ninterface IPair is IERC20 {\n function token0() external view returns (address);\n\n function token1() external view returns (address);\n\n function getReserves()\n external\n view\n returns (\n uint112,\n uint112,\n uint32\n );\n}\n\ncontract BoringCryptoDashboardV2 {\n using SafeMath for uint256;\n\n struct PairFull {\n address token;\n address token0;\n address token1;\n uint256 reserve0;\n uint256 reserve1;\n uint256 totalSupply;\n uint256 balance;\n }\n\n function getPairsFull(address who, address[] calldata addresses) public view returns (PairFull[] memory) {\n PairFull[] memory pairs = new PairFull[](addresses.length);\n for (uint256 i = 0; i < addresses.length; i++) {\n address token = addresses[i];\n pairs[i].token = token;\n pairs[i].token0 = IPair(token).token0();\n pairs[i].token1 = IPair(token).token1();\n (uint256 reserve0, uint256 reserve1, ) = IPair(token).getReserves();\n pairs[i].reserve0 = reserve0;\n pairs[i].reserve1 = reserve1;\n pairs[i].balance = IERC20(token).balanceOf(who);\n pairs[i].totalSupply = IERC20(token).totalSupply();\n }\n return pairs;\n }\n\n struct PoolsInfo {\n uint256 totalAllocPoint;\n uint256 poolLength;\n }\n\n struct PoolInfo {\n uint256 pid;\n IPair lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. SUSHIs to distribute per block.\n address token0;\n address token1;\n }\n\n IMasterChef chef;\n IFactory pangolinFactory;\n IFactory joeFactory;\n address wavax;\n\n constructor(\n address _chef,\n address _pangolinFactory,\n address _joeFactory,\n address _wavax\n ) public {\n chef = IMasterChef(_chef);\n pangolinFactory = IFactory(_pangolinFactory);\n joeFactory = IFactory(_joeFactory);\n wavax = _wavax;\n }\n\n function getPools(uint256[] calldata pids) public view returns (PoolsInfo memory, PoolInfo[] memory) {\n PoolsInfo memory info;\n info.totalAllocPoint = chef.totalAllocPoint();\n uint256 poolLength = chef.poolLength();\n info.poolLength = poolLength;\n\n PoolInfo[] memory pools = new PoolInfo[](pids.length);\n\n for (uint256 i = 0; i < pids.length; i++) {\n pools[i].pid = pids[i];\n (address lpToken, uint256 allocPoint, , ) = chef.poolInfo(pids[i]);\n IPair pair = IPair(lpToken);\n pools[i].lpToken = pair;\n pools[i].allocPoint = allocPoint;\n\n pools[i].token0 = pair.token0();\n pools[i].token1 = pair.token1();\n }\n return (info, pools);\n }\n\n function findPools(address who, uint256[] calldata pids) public view returns (PoolInfo[] memory) {\n uint256 count;\n\n for (uint256 i = 0; i < pids.length; i++) {\n (uint256 balance, ) = chef.userInfo(pids[i], who);\n if (balance > 0) {\n count++;\n }\n }\n\n PoolInfo[] memory pools = new PoolInfo[](count);\n\n count = 0;\n for (uint256 i = 0; i < pids.length; i++) {\n (uint256 balance, ) = chef.userInfo(pids[i], who);\n if (balance > 0) {\n pools[count].pid = pids[i];\n (address lpToken, uint256 allocPoint, , ) = chef.poolInfo(pids[i]);\n IPair pair = IPair(lpToken);\n pools[count].lpToken = pair;\n pools[count].allocPoint = allocPoint;\n\n pools[count].token0 = pair.token0();\n pools[count].token1 = pair.token1();\n count++;\n }\n }\n\n return pools;\n }\n\n function getAVAXRate(address token) public view returns (uint256) {\n uint256 avax_rate = 1e18;\n if (token != wavax) {\n IPair pairPangolin;\n IPair pairJoe;\n pairPangolin = IPair(IFactory(pangolinFactory).getPair(token, wavax));\n pairJoe = IPair(IFactory(joeFactory).getPair(token, wavax));\n if (address(pairPangolin) == address(0) && address(pairJoe) == address(0)) {\n return 0;\n }\n\n uint112 reserve0Pangolin;\n uint112 reserve1Pangolin;\n uint112 reserve0Joe;\n uint112 reserve1Joe;\n\n if (address(pairPangolin) != address(0)) {\n (reserve0Pangolin, reserve1Pangolin, ) = pairPangolin.getReserves();\n }\n if (address(pairJoe) != address(0)) {\n (reserve0Joe, reserve1Joe, ) = pairJoe.getReserves();\n }\n\n if (address(pairJoe) == address(0) || reserve0Pangolin > reserve0Joe || reserve1Pangolin > reserve1Joe) {\n if (pairPangolin.token0() == wavax) {\n avax_rate = uint256(reserve1Pangolin).mul(1e18).div(reserve0Pangolin);\n } else {\n avax_rate = uint256(reserve0Pangolin).mul(1e18).div(reserve1Pangolin);\n }\n } else {\n if (pairJoe.token0() == wavax) {\n avax_rate = uint256(reserve1Joe).mul(1e18).div(reserve0Joe);\n } else {\n avax_rate = uint256(reserve0Joe).mul(1e18).div(reserve1Joe);\n }\n }\n }\n return avax_rate;\n }\n\n struct UserPoolInfo {\n uint256 pid;\n uint256 balance; // Balance of pool tokens\n uint256 totalSupply; // Token staked lp tokens\n uint256 lpBalance; // Balance of lp tokens not staked\n uint256 lpTotalSupply; // TotalSupply of lp tokens\n uint256 lpAllowance; // LP tokens approved for masterchef\n uint256 reserve0;\n uint256 reserve1;\n uint256 token0rate;\n uint256 token1rate;\n uint256 rewardDebt;\n uint256 pending; // Pending JOE\n }\n\n function pollPools(address who, uint256[] calldata pids) public view returns (UserPoolInfo[] memory) {\n UserPoolInfo[] memory pools = new UserPoolInfo[](pids.length);\n\n for (uint256 i = 0; i < pids.length; i++) {\n (uint256 amount, ) = chef.userInfo(pids[i], who);\n pools[i].balance = amount;\n (uint256 pendingJoe, , , ) = chef.pendingTokens(pids[i], who);\n pools[i].pending = pendingJoe;\n\n (address lpToken, , , ) = chef.poolInfo(pids[i]);\n pools[i].pid = pids[i];\n IPair pair = IPair(lpToken);\n pools[i].totalSupply = pair.balanceOf(address(chef));\n pools[i].lpAllowance = pair.allowance(who, address(chef));\n pools[i].lpBalance = pair.balanceOf(who);\n pools[i].lpTotalSupply = pair.totalSupply();\n pools[i].token0rate = getAVAXRate(pair.token0());\n pools[i].token1rate = getAVAXRate(pair.token1());\n\n (uint112 reserve0, uint112 reserve1, ) = pair.getReserves();\n pools[i].reserve0 = reserve0;\n pools[i].reserve1 = reserve1;\n }\n return pools;\n }\n}\n" + }, + "contracts/JoeVote.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"./interfaces/IPair.sol\";\nimport \"./interfaces/IBar.sol\";\n\ninterface IMasterChef {\n function userInfo(uint256 pid, address owner) external view returns (uint256, uint256);\n}\n\ncontract JoeVote {\n using SafeMath for uint256;\n\n IPair pair; // JOE-AVAX LP\n IBar bar;\n IERC20 joe;\n IMasterChef chef;\n uint256 pid; // Pool ID of the JOE-AVAX LP in MasterChefV2\n\n function name() public pure returns (string memory) {\n return \"JoeVote\";\n }\n\n function symbol() public pure returns (string memory) {\n return \"JOEVOTE\";\n }\n\n function decimals() public pure returns (uint8) {\n return 18;\n }\n\n constructor(\n address _pair,\n address _bar,\n address _joe,\n address _chef,\n uint256 _pid\n ) public {\n pair = IPair(_pair);\n bar = IBar(_bar);\n joe = IERC20(_joe);\n chef = IMasterChef(_chef);\n pid = _pid;\n }\n\n function totalSupply() public view returns (uint256) {\n (uint256 lp_totalJoe, , ) = pair.getReserves();\n uint256 xjoe_totalJoe = joe.balanceOf(address(bar));\n\n return lp_totalJoe.mul(2).add(xjoe_totalJoe);\n }\n\n function balanceOf(address owner) public view returns (uint256) {\n //////////////////////////\n // Get balance from LPs //\n //////////////////////////\n uint256 lp_totalJoe = joe.balanceOf(address(pair));\n uint256 lp_total = pair.totalSupply();\n uint256 lp_balance = pair.balanceOf(owner);\n\n // Add staked balance\n (uint256 lp_stakedBalance, ) = chef.userInfo(pid, owner);\n lp_balance = lp_balance.add(lp_stakedBalance);\n\n // LP voting power is 2x the users JOE share in the pool.\n uint256 lp_powah = lp_totalJoe.mul(lp_balance).div(lp_total).mul(2);\n\n ///////////////////////////\n // Get balance from xJOE //\n ///////////////////////////\n\n uint256 xjoe_balance = bar.balanceOf(owner);\n uint256 xjoe_total = bar.totalSupply();\n uint256 xjoe_totalJoe = joe.balanceOf(address(bar));\n\n // xJOE voting power is the users JOE share in the bar\n uint256 xjoe_powah = xjoe_totalJoe.mul(xjoe_balance).div(xjoe_total);\n\n //////////////////////////\n // Get balance from JOE //\n //////////////////////////\n\n uint256 joe_balance = joe.balanceOf(owner);\n\n return lp_powah.add(xjoe_powah).add(joe_balance);\n }\n\n function allowance(address, address) public pure returns (uint256) {\n return 0;\n }\n\n function transfer(address, uint256) public pure returns (bool) {\n return false;\n }\n\n function approve(address, uint256) public pure returns (bool) {\n return false;\n }\n\n function transferFrom(\n address,\n address,\n uint256\n ) public pure returns (bool) {\n return false;\n }\n}\n" + }, + "contracts/interfaces/IBar.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\ninterface IBar {\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n}\n" + }, + "contracts/boringcrypto/BoringBatchable.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\n// solhint-disable avoid-low-level-calls\n// solhint-disable no-inline-assembly\n\n// Audit on 5-Jan-2021 by Keno and BoringCrypto\n// WARNING!!!\n// Combining BoringBatchable with msg.value can cause double spending issues\n// https://www.paradigm.xyz/2021/08/two-rights-might-make-a-wrong/\n\nimport \"../interfaces/IERC20.sol\";\n\ncontract BaseBoringBatchable {\n /// @dev Helper function to extract a useful revert message from a failed call.\n /// If the returned data is malformed or not correctly abi encoded then this call can fail itself.\n function _getRevertMsg(bytes memory _returnData) internal pure returns (string memory) {\n // If the _res length is less than 68, then the transaction failed silently (without a revert message)\n if (_returnData.length < 68) return \"Transaction reverted silently\";\n\n assembly {\n // Slice the sighash.\n _returnData := add(_returnData, 0x04)\n }\n return abi.decode(_returnData, (string)); // All that remains is the revert string\n }\n\n /// @notice Allows batched call to self (this contract).\n /// @param calls An array of inputs for each call.\n /// @param revertOnFail If True then reverts after a failed call and stops doing further calls.\n // F1: External is ok here because this is the batch function, adding it to a batch makes no sense\n // F2: Calls in the batch may be payable, delegatecall operates in the same context, so each call in the batch has access to msg.value\n // C3: The length of the loop is fully under user control, so can't be exploited\n // C7: Delegatecall is only used on the same contract, so it's safe\n function batch(bytes[] calldata calls, bool revertOnFail) external payable {\n for (uint256 i = 0; i < calls.length; i++) {\n (bool success, bytes memory result) = address(this).delegatecall(calls[i]);\n if (!success && revertOnFail) {\n revert(_getRevertMsg(result));\n }\n }\n }\n}\n\ncontract BoringBatchable is BaseBoringBatchable {\n /// @notice Call wrapper that performs `ERC20.permit` on `token`.\n /// Lookup `IERC20.permit`.\n // F6: Parameters can be used front-run the permit and the user's permit will fail (due to nonce or other revert)\n // if part of a batch this could be used to grief once as the second call would not need the permit\n function permitToken(\n IERC20 token,\n address from,\n address to,\n uint256 amount,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) public {\n token.permit(from, to, amount, deadline, v, r, s);\n }\n}\n" + }, + "contracts/MasterChefJoe.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/utils/EnumerableSet.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./JoeToken.sol\";\n\n// MasterChefJoe is a boss. He says \"go f your blocks lego boy, I'm gonna use timestamp instead\".\n// And to top it off, it takes no risks. Because the biggest risk is operator error.\n// So we make it virtually impossible for the operator of this contract to cause a bug with people's harvests.\n//\n// Note that it's ownable and the owner wields tremendous power. The ownership\n// will be transferred to a governance smart contract once JOE is sufficiently\n// distributed and the community can show to govern itself.\n//\n// With thanks to the Lydia Finance team.\n//\n// Godspeed and may the 10x be with you.\ncontract MasterChefJoe is Ownable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n // Info of each user.\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n //\n // We do some fancy math here. Basically, any point in time, the amount of JOEs\n // entitled to a user but is pending to be distributed is:\n //\n // pending reward = (user.amount * pool.accJoePerShare) - user.rewardDebt\n //\n // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:\n // 1. The pool's `accJoePerShare` (and `lastRewardTimestamp`) gets updated.\n // 2. User receives the pending reward sent to his/her address.\n // 3. User's `amount` gets updated.\n // 4. User's `rewardDebt` gets updated.\n }\n\n // Info of each pool.\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOEs to distribute per second.\n uint256 lastRewardTimestamp; // Last timestamp that JOEs distribution occurs.\n uint256 accJoePerShare; // Accumulated JOEs per share, times 1e12. See below.\n }\n\n // The JOE TOKEN!\n JoeToken public joe;\n // Dev address.\n address public devaddr;\n // Treasury address.\n address public treasuryaddr;\n // JOE tokens created per second.\n uint256 public joePerSec;\n // Percentage of pool rewards that goto the devs.\n uint256 public devPercent; // 20%\n // Percentage of pool rewards that goes to the treasury.\n uint256 public treasuryPercent; // 20%\n\n // Info of each pool.\n PoolInfo[] public poolInfo;\n // Mapping to check which LP tokens have been added as pools.\n mapping(IERC20 => bool) public isPool;\n // Info of each user that stakes LP tokens.\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n // Total allocation points. Must be the sum of all allocation points in all pools.\n uint256 public totalAllocPoint = 0;\n // The timestamp when JOE mining starts.\n uint256 public startTimestamp;\n\n event Add(address indexed lpToken, uint256 allocPoint);\n event Set(uint256 indexed pid, uint256 allocPoint);\n event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\n event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event SetDevAddress(address indexed oldAddress, address indexed newAddress);\n event UpdateEmissionRate(address indexed user, uint256 _joePerSec);\n\n constructor(\n JoeToken _joe,\n address _devaddr,\n address _treasuryaddr,\n uint256 _joePerSec,\n uint256 _startTimestamp,\n uint256 _devPercent,\n uint256 _treasuryPercent\n ) public {\n require(0 <= _devPercent && _devPercent <= 1000, \"constructor: invalid dev percent value\");\n require(0 <= _treasuryPercent && _treasuryPercent <= 1000, \"constructor: invalid treasury percent value\");\n require(_devPercent + _treasuryPercent <= 1000, \"constructor: total percent over max\");\n joe = _joe;\n devaddr = _devaddr;\n treasuryaddr = _treasuryaddr;\n joePerSec = _joePerSec;\n startTimestamp = _startTimestamp;\n devPercent = _devPercent;\n treasuryPercent = _treasuryPercent;\n }\n\n function poolLength() external view returns (uint256) {\n return poolInfo.length;\n }\n\n // Add a new lp to the pool. Can only be called by the owner.\n // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.\n function add(uint256 _allocPoint, IERC20 _lpToken) public onlyOwner {\n require(!isPool[_lpToken], \"add: LP already added\");\n massUpdatePools();\n uint256 lastRewardTimestamp = block.timestamp > startTimestamp ? block.timestamp : startTimestamp;\n totalAllocPoint = totalAllocPoint.add(_allocPoint);\n poolInfo.push(\n PoolInfo({\n lpToken: _lpToken,\n allocPoint: _allocPoint,\n lastRewardTimestamp: lastRewardTimestamp,\n accJoePerShare: 0\n })\n );\n isPool[_lpToken] = true;\n emit Add(address(_lpToken), _allocPoint);\n }\n\n // Update the given pool's JOE allocation point. Can only be called by the owner.\n function set(uint256 _pid, uint256 _allocPoint) public onlyOwner {\n massUpdatePools();\n totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);\n poolInfo[_pid].allocPoint = _allocPoint;\n emit Set(_pid, _allocPoint);\n }\n\n // View function to see pending JOEs on frontend.\n function pendingJoe(uint256 _pid, address _user) external view returns (uint256) {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_user];\n uint256 accJoePerShare = pool.accJoePerShare;\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (block.timestamp > pool.lastRewardTimestamp && lpSupply != 0) {\n uint256 multiplier = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 joeReward = multiplier\n .mul(joePerSec)\n .mul(pool.allocPoint)\n .div(totalAllocPoint)\n .mul(1000 - devPercent - treasuryPercent)\n .div(1000);\n accJoePerShare = accJoePerShare.add(joeReward.mul(1e12).div(lpSupply));\n }\n return user.amount.mul(accJoePerShare).div(1e12).sub(user.rewardDebt);\n }\n\n // Update reward variables for all pools. Be careful of gas spending!\n function massUpdatePools() public {\n uint256 length = poolInfo.length;\n for (uint256 pid = 0; pid < length; ++pid) {\n updatePool(pid);\n }\n }\n\n // Update reward variables of the given pool to be up-to-date.\n function updatePool(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n if (block.timestamp <= pool.lastRewardTimestamp) {\n return;\n }\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (lpSupply == 0) {\n pool.lastRewardTimestamp = block.timestamp;\n return;\n }\n uint256 multiplier = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 joeReward = multiplier.mul(joePerSec).mul(pool.allocPoint).div(totalAllocPoint);\n uint256 lpPercent = 1000 - devPercent - treasuryPercent;\n joe.mint(devaddr, joeReward.mul(devPercent).div(1000));\n joe.mint(treasuryaddr, joeReward.mul(treasuryPercent).div(1000));\n joe.mint(address(this), joeReward.mul(lpPercent).div(1000));\n pool.accJoePerShare = pool.accJoePerShare.add(joeReward.mul(1e12).div(lpSupply).mul(lpPercent).div(1000));\n pool.lastRewardTimestamp = block.timestamp;\n }\n\n // Deposit LP tokens to MasterChef for JOE allocation.\n function deposit(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n updatePool(_pid);\n if (user.amount > 0) {\n uint256 pending = user.amount.mul(pool.accJoePerShare).div(1e12).sub(user.rewardDebt);\n safeJoeTransfer(msg.sender, pending);\n }\n pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);\n user.amount = user.amount.add(_amount);\n user.rewardDebt = user.amount.mul(pool.accJoePerShare).div(1e12);\n emit Deposit(msg.sender, _pid, _amount);\n }\n\n // Withdraw LP tokens from MasterChef.\n function withdraw(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n require(user.amount >= _amount, \"withdraw: not good\");\n\n updatePool(_pid);\n uint256 pending = user.amount.mul(pool.accJoePerShare).div(1e12).sub(user.rewardDebt);\n safeJoeTransfer(msg.sender, pending);\n user.amount = user.amount.sub(_amount);\n pool.lpToken.safeTransfer(address(msg.sender), _amount);\n user.rewardDebt = user.amount.mul(pool.accJoePerShare).div(1e12);\n emit Withdraw(msg.sender, _pid, _amount);\n }\n\n // Withdraw without caring about rewards. EMERGENCY ONLY.\n function emergencyWithdraw(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n pool.lpToken.safeTransfer(address(msg.sender), user.amount);\n emit EmergencyWithdraw(msg.sender, _pid, user.amount);\n user.amount = 0;\n user.rewardDebt = 0;\n }\n\n // Safe joe transfer function, just in case if rounding error causes pool to not have enough JOEs.\n function safeJoeTransfer(address _to, uint256 _amount) internal {\n uint256 joeBal = joe.balanceOf(address(this));\n if (_amount > joeBal) {\n joe.transfer(_to, joeBal);\n } else {\n joe.transfer(_to, _amount);\n }\n }\n\n // Update dev address by the previous dev.\n function dev(address _devaddr) public {\n require(msg.sender == devaddr, \"dev: wut?\");\n devaddr = _devaddr;\n emit SetDevAddress(msg.sender, _devaddr);\n }\n\n function setDevPercent(uint256 _newDevPercent) public onlyOwner {\n require(0 <= _newDevPercent && _newDevPercent <= 1000, \"setDevPercent: invalid percent value\");\n require(treasuryPercent + _newDevPercent <= 1000, \"setDevPercent: total percent over max\");\n devPercent = _newDevPercent;\n }\n\n function setTreasuryPercent(uint256 _newTreasuryPercent) public onlyOwner {\n require(0 <= _newTreasuryPercent && _newTreasuryPercent <= 1000, \"setTreasuryPercent: invalid percent value\");\n require(devPercent + _newTreasuryPercent <= 1000, \"setTreasuryPercent: total percent over max\");\n treasuryPercent = _newTreasuryPercent;\n }\n\n // Pancake has to add hidden dummy pools inorder to alter the emission,\n // here we make it simple and transparent to all.\n function updateEmissionRate(uint256 _joePerSec) public onlyOwner {\n massUpdatePools();\n joePerSec = _joePerSec;\n emit UpdateEmissionRate(msg.sender, _joePerSec);\n }\n}\n" + }, + "contracts/Cliff.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/math/Math.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\n\n/**\n * @title Cliff\n * @dev A token holder contract that can release its token balance with a cliff period.\n * Optionally revocable by the owner.\n */\ncontract Cliff {\n using SafeERC20 for IERC20;\n using SafeMath for uint256;\n\n uint256 public constant SECONDS_PER_MONTH = 30 days;\n\n event Released(uint256 amount);\n\n // beneficiary of tokens after they are released\n address public immutable beneficiary;\n IERC20 public immutable token;\n\n uint256 public immutable cliffInMonths;\n uint256 public immutable startTimestamp;\n uint256 public released;\n\n /**\n * @dev Creates a cliff contract that locks its balance of any ERC20 token and\n * only allows release to the beneficiary once the cliff has passed.\n * @param _beneficiary address of the beneficiary to whom vested tokens are transferred\n * @param _cliffInMonths duration in months of the cliff in which tokens will begin to vest\n */\n constructor(\n address _token,\n address _beneficiary,\n uint256 _startTimestamp,\n uint256 _cliffInMonths\n ) public {\n require(_beneficiary != address(0), \"Cliff: Beneficiary cannot be empty\");\n\n token = IERC20(_token);\n beneficiary = _beneficiary;\n cliffInMonths = _cliffInMonths;\n startTimestamp = _startTimestamp == 0 ? blockTimestamp() : _startTimestamp;\n }\n\n /**\n * @notice Transfers vested tokens to beneficiary.\n */\n function release() external {\n uint256 vested = vestedAmount();\n require(vested > 0, \"Cliff: No tokens to release\");\n\n released = released.add(vested);\n token.safeTransfer(beneficiary, vested);\n\n emit Released(vested);\n }\n\n /**\n * @dev Calculates the amount that has already vested but hasn't been released yet.\n */\n function vestedAmount() public view returns (uint256) {\n if (blockTimestamp() < startTimestamp) {\n return 0;\n }\n\n uint256 elapsedTime = blockTimestamp().sub(startTimestamp);\n uint256 elapsedMonths = elapsedTime.div(SECONDS_PER_MONTH);\n\n if (elapsedMonths < cliffInMonths) {\n return 0;\n } else {\n return token.balanceOf(address(this));\n }\n }\n\n function blockTimestamp() public view virtual returns (uint256) {\n return block.timestamp;\n }\n}\n" + }, + "@openzeppelin/contracts/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return a >= b ? a : b;\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return a < b ? a : b;\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow, so we distribute\n return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);\n }\n}\n" + }, + "contracts/JoeMakerV2.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// P1 - P3: OK\npragma solidity 0.6.12;\n\nimport \"./libraries/SafeMath.sol\";\nimport \"./libraries/SafeERC20.sol\";\n\nimport \"./traderjoe/interfaces/IERC20.sol\";\nimport \"./traderjoe/interfaces/IJoeERC20.sol\";\nimport \"./traderjoe/interfaces/IJoePair.sol\";\nimport \"./traderjoe/interfaces/IJoeFactory.sol\";\n\nimport \"./boringcrypto/BoringOwnable.sol\";\n\n// JoeMakerV2 is MasterJoe's left hand and kinda a wizard. He can cook up Joe from pretty much anything!\n// This contract handles \"serving up\" rewards for xJoe holders by trading tokens collected from fees for Joe.\n\n// T1 - T4: OK\ncontract JoeMakerV2 is BoringOwnable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n /* ========== CONSTANT VARIABLES ========== */\n\n IJoeFactory public immutable factory;\n address public immutable bar;\n address private immutable joe;\n address private immutable wavax;\n\n mapping(address => address) internal _bridges;\n\n event LogBridgeSet(address indexed token, address indexed bridge);\n\n event LogConvert(\n address indexed server,\n address indexed token0,\n address indexed token1,\n uint256 amount0,\n uint256 amount1,\n uint256 amountJOE\n );\n\n /* ========== CONSTRUCTOR ========== */\n\n constructor(\n address _factory,\n address _bar,\n address _joe,\n address _wavax\n ) public {\n factory = IJoeFactory(_factory);\n bar = _bar;\n joe = _joe;\n wavax = _wavax;\n }\n\n /* ========== External Functions ========== */\n\n // F3: _convert is separate to save gas by only checking the 'onlyEOA' modifier once in case of convertMultiple\n // F6: There is an exploit to add lots of JOE to the bar, run convert, then remove the JOE again.\n // As the size of the JoeBar has grown, this requires large amounts of funds and isn't super profitable anymore\n // The onlyEOA modifier prevents this being done with a flash loan.\n function convert(address token0, address token1) external onlyEOA {\n _convert(token0, token1);\n }\n\n function convertMultiple(address[] calldata token0, address[] calldata token1) external onlyEOA {\n // TODO: This can be optimized a fair bit, but this is safer and simpler for now\n uint256 len = token0.length;\n for (uint256 i = 0; i < len; i++) {\n _convert(token0[i], token1[i]);\n }\n }\n\n /* ========== Modifiers ========== */\n\n // It's not a fool proof solution, but it prevents flash loans, so here it's ok to use tx.origin\n modifier onlyEOA() {\n // Try to make flash-loan exploit harder to do by only allowing externally owned addresses.\n require(msg.sender == tx.origin, \"JoeMakerV2: must use EOA\");\n _;\n }\n\n /* ========== Public Functions ========== */\n\n function bridgeFor(address token) public view returns (address bridge) {\n bridge = _bridges[token];\n if (bridge == address(0)) {\n bridge = wavax;\n }\n }\n\n /* ========== Internal Functions ========== */\n\n function _convert(address token0, address token1) internal {\n // Interactions\n // S1 - S4: OK\n IJoePair pair = IJoePair(factory.getPair(token0, token1));\n require(address(pair) != address(0), \"JoeMakerV2: Invalid pair\");\n // balanceOf: S1 - S4: OK\n // transfer: X1 - X5: OK\n IERC20(address(pair)).safeTransfer(address(pair), pair.balanceOf(address(this)));\n\n // X1 - X5: OK\n // We don't take amount0 and amount1 from here, as it won't take into account reflect tokens.\n pair.burn(address(this));\n\n // We get the amount0 and amount1 by their respective balance of JoeMakerV2.\n uint256 amount0 = IERC20(token0).balanceOf(address(this));\n uint256 amount1 = IERC20(token1).balanceOf(address(this));\n\n emit LogConvert(msg.sender, token0, token1, amount0, amount1, _convertStep(token0, token1, amount0, amount1));\n }\n\n function _convertStep(\n address token0,\n address token1,\n uint256 amount0,\n uint256 amount1\n ) internal returns (uint256 joeOut) {\n // Interactions\n if (token0 == token1) {\n uint256 amount = amount0.add(amount1);\n if (token0 == joe) {\n IERC20(joe).safeTransfer(bar, amount);\n joeOut = amount;\n } else if (token0 == wavax) {\n joeOut = _toJOE(wavax, amount);\n } else {\n address bridge = bridgeFor(token0);\n amount = _swap(token0, bridge, amount, address(this));\n joeOut = _convertStep(bridge, bridge, amount, 0);\n }\n } else if (token0 == joe) {\n // eg. JOE - AVAX\n IERC20(joe).safeTransfer(bar, amount0);\n joeOut = _toJOE(token1, amount1).add(amount0);\n } else if (token1 == joe) {\n // eg. USDT - JOE\n IERC20(joe).safeTransfer(bar, amount1);\n joeOut = _toJOE(token0, amount0).add(amount1);\n } else if (token0 == wavax) {\n // eg. AVAX - USDC\n joeOut = _toJOE(wavax, _swap(token1, wavax, amount1, address(this)).add(amount0));\n } else if (token1 == wavax) {\n // eg. USDT - AVAX\n joeOut = _toJOE(wavax, _swap(token0, wavax, amount0, address(this)).add(amount1));\n } else {\n // eg. MIC - USDT\n address bridge0 = bridgeFor(token0);\n address bridge1 = bridgeFor(token1);\n if (bridge0 == token1) {\n // eg. MIC - USDT - and bridgeFor(MIC) = USDT\n joeOut = _convertStep(bridge0, token1, _swap(token0, bridge0, amount0, address(this)), amount1);\n } else if (bridge1 == token0) {\n // eg. WBTC - DSD - and bridgeFor(DSD) = WBTC\n joeOut = _convertStep(token0, bridge1, amount0, _swap(token1, bridge1, amount1, address(this)));\n } else {\n joeOut = _convertStep(\n bridge0,\n bridge1, // eg. USDT - DSD - and bridgeFor(DSD) = WBTC\n _swap(token0, bridge0, amount0, address(this)),\n _swap(token1, bridge1, amount1, address(this))\n );\n }\n }\n }\n\n function _swap(\n address fromToken,\n address toToken,\n uint256 amountIn,\n address to\n ) internal returns (uint256 realAmountOut) {\n // Checks\n // X1 - X5: OK\n IJoePair pair = IJoePair(factory.getPair(fromToken, toToken));\n require(address(pair) != address(0), \"JoeMakerV2: Cannot convert\");\n\n // Interactions\n // X1 - X5: OK\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n\n IERC20(fromToken).safeTransfer(address(pair), amountIn);\n\n // Added in case fromToken is a reflect token.\n if (fromToken == pair.token0()) {\n amountIn = IERC20(fromToken).balanceOf(address(pair)) - reserve0;\n } else {\n amountIn = IERC20(fromToken).balanceOf(address(pair)) - reserve1;\n }\n\n uint256 balanceBefore = IERC20(toToken).balanceOf(to);\n\n uint256 amountInWithFee = amountIn.mul(997);\n if (fromToken == pair.token0()) {\n uint256 amountOut = amountInWithFee.mul(reserve1) / reserve0.mul(1000).add(amountInWithFee);\n pair.swap(0, amountOut, to, new bytes(0));\n // TODO: Add maximum slippage?\n } else {\n uint256 amountOut = amountInWithFee.mul(reserve0) / reserve1.mul(1000).add(amountInWithFee);\n pair.swap(amountOut, 0, to, new bytes(0));\n // TODO: Add maximum slippage?\n }\n\n realAmountOut = IERC20(toToken).balanceOf(to) - balanceBefore;\n }\n\n function _toJOE(address token, uint256 amountIn) internal returns (uint256 amountOut) {\n // X1 - X5: OK\n amountOut = _swap(token, joe, amountIn, bar);\n }\n\n /* ========== RESTRICTED FUNCTIONS ========== */\n\n function setBridge(address token, address bridge) external onlyOwner {\n // Checks\n require(token != joe && token != wavax && token != bridge, \"JoeMakerV2: Invalid bridge\");\n\n // Effects\n _bridges[token] = bridge;\n emit LogBridgeSet(token, bridge);\n }\n}\n" + }, + "contracts/JoeMaker.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// P1 - P3: OK\npragma solidity 0.6.12;\nimport \"./libraries/SafeMath.sol\";\nimport \"./libraries/SafeERC20.sol\";\n\nimport \"./traderjoe/interfaces/IJoeERC20.sol\";\nimport \"./traderjoe/interfaces/IJoePair.sol\";\nimport \"./traderjoe/interfaces/IJoeFactory.sol\";\n\nimport \"./boringcrypto/BoringOwnable.sol\";\n\n// JoeMaker is MasterJoe's left hand and kinda a wizard. He can cook up Joe from pretty much anything!\n// This contract handles \"serving up\" rewards for xJoe holders by trading tokens collected from fees for Joe.\n\n// T1 - T4: OK\ncontract JoeMaker is BoringOwnable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n // V1 - V5: OK\n IJoeFactory public immutable factory;\n //0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac\n // V1 - V5: OK\n address public immutable bar;\n //0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272\n // V1 - V5: OK\n address private immutable joe;\n //0x6B3595068778DD592e39A122f4f5a5cF09C90fE2\n // V1 - V5: OK\n address private immutable wavax;\n //0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\n\n // V1 - V5: OK\n mapping(address => address) internal _bridges;\n\n // E1: OK\n event LogBridgeSet(address indexed token, address indexed bridge);\n // E1: OK\n event LogConvert(\n address indexed server,\n address indexed token0,\n address indexed token1,\n uint256 amount0,\n uint256 amount1,\n uint256 amountJOE\n );\n\n constructor(\n address _factory,\n address _bar,\n address _joe,\n address _wavax\n ) public {\n factory = IJoeFactory(_factory);\n bar = _bar;\n joe = _joe;\n wavax = _wavax;\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n function bridgeFor(address token) public view returns (address bridge) {\n bridge = _bridges[token];\n if (bridge == address(0)) {\n bridge = wavax;\n }\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n function setBridge(address token, address bridge) external onlyOwner {\n // Checks\n require(token != joe && token != wavax && token != bridge, \"JoeMaker: Invalid bridge\");\n\n // Effects\n _bridges[token] = bridge;\n emit LogBridgeSet(token, bridge);\n }\n\n // M1 - M5: OK\n // C1 - C24: OK\n // C6: It's not a fool proof solution, but it prevents flash loans, so here it's ok to use tx.origin\n modifier onlyEOA() {\n // Try to make flash-loan exploit harder to do by only allowing externally owned addresses.\n require(msg.sender == tx.origin, \"JoeMaker: must use EOA\");\n _;\n }\n\n // F1 - F10: OK\n // F3: _convert is separate to save gas by only checking the 'onlyEOA' modifier once in case of convertMultiple\n // F6: There is an exploit to add lots of JOE to the bar, run convert, then remove the JOE again.\n // As the size of the JoeBar has grown, this requires large amounts of funds and isn't super profitable anymore\n // The onlyEOA modifier prevents this being done with a flash loan.\n // C1 - C24: OK\n function convert(address token0, address token1) external onlyEOA {\n _convert(token0, token1);\n }\n\n // F1 - F10: OK, see convert\n // C1 - C24: OK\n // C3: Loop is under control of the caller\n function convertMultiple(address[] calldata token0, address[] calldata token1) external onlyEOA {\n // TODO: This can be optimized a fair bit, but this is safer and simpler for now\n uint256 len = token0.length;\n for (uint256 i = 0; i < len; i++) {\n _convert(token0[i], token1[i]);\n }\n }\n\n // F1 - F10: OK\n // C1- C24: OK\n function _convert(address token0, address token1) internal {\n // Interactions\n // S1 - S4: OK\n IJoePair pair = IJoePair(factory.getPair(token0, token1));\n require(address(pair) != address(0), \"JoeMaker: Invalid pair\");\n // balanceOf: S1 - S4: OK\n // transfer: X1 - X5: OK\n IERC20(address(pair)).safeTransfer(address(pair), pair.balanceOf(address(this)));\n // X1 - X5: OK\n (uint256 amount0, uint256 amount1) = pair.burn(address(this));\n if (token0 != pair.token0()) {\n (amount0, amount1) = (amount1, amount0);\n }\n emit LogConvert(msg.sender, token0, token1, amount0, amount1, _convertStep(token0, token1, amount0, amount1));\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n // All safeTransfer, _swap, _toJOE, _convertStep: X1 - X5: OK\n function _convertStep(\n address token0,\n address token1,\n uint256 amount0,\n uint256 amount1\n ) internal returns (uint256 joeOut) {\n // Interactions\n if (token0 == token1) {\n uint256 amount = amount0.add(amount1);\n if (token0 == joe) {\n IERC20(joe).safeTransfer(bar, amount);\n joeOut = amount;\n } else if (token0 == wavax) {\n joeOut = _toJOE(wavax, amount);\n } else {\n address bridge = bridgeFor(token0);\n amount = _swap(token0, bridge, amount, address(this));\n joeOut = _convertStep(bridge, bridge, amount, 0);\n }\n } else if (token0 == joe) {\n // eg. JOE - AVAX\n IERC20(joe).safeTransfer(bar, amount0);\n joeOut = _toJOE(token1, amount1).add(amount0);\n } else if (token1 == joe) {\n // eg. USDT - JOE\n IERC20(joe).safeTransfer(bar, amount1);\n joeOut = _toJOE(token0, amount0).add(amount1);\n } else if (token0 == wavax) {\n // eg. AVAX - USDC\n joeOut = _toJOE(wavax, _swap(token1, wavax, amount1, address(this)).add(amount0));\n } else if (token1 == wavax) {\n // eg. USDT - AVAX\n joeOut = _toJOE(wavax, _swap(token0, wavax, amount0, address(this)).add(amount1));\n } else {\n // eg. MIC - USDT\n address bridge0 = bridgeFor(token0);\n address bridge1 = bridgeFor(token1);\n if (bridge0 == token1) {\n // eg. MIC - USDT - and bridgeFor(MIC) = USDT\n joeOut = _convertStep(bridge0, token1, _swap(token0, bridge0, amount0, address(this)), amount1);\n } else if (bridge1 == token0) {\n // eg. WBTC - DSD - and bridgeFor(DSD) = WBTC\n joeOut = _convertStep(token0, bridge1, amount0, _swap(token1, bridge1, amount1, address(this)));\n } else {\n joeOut = _convertStep(\n bridge0,\n bridge1, // eg. USDT - DSD - and bridgeFor(DSD) = WBTC\n _swap(token0, bridge0, amount0, address(this)),\n _swap(token1, bridge1, amount1, address(this))\n );\n }\n }\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n // All safeTransfer, swap: X1 - X5: OK\n function _swap(\n address fromToken,\n address toToken,\n uint256 amountIn,\n address to\n ) internal returns (uint256 amountOut) {\n // Checks\n // X1 - X5: OK\n IJoePair pair = IJoePair(factory.getPair(fromToken, toToken));\n require(address(pair) != address(0), \"JoeMaker: Cannot convert\");\n\n // Interactions\n // X1 - X5: OK\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n uint256 amountInWithFee = amountIn.mul(997);\n if (fromToken == pair.token0()) {\n amountOut = amountIn.mul(997).mul(reserve1) / reserve0.mul(1000).add(amountInWithFee);\n IERC20(fromToken).safeTransfer(address(pair), amountIn);\n pair.swap(0, amountOut, to, new bytes(0));\n // TODO: Add maximum slippage?\n } else {\n amountOut = amountIn.mul(997).mul(reserve0) / reserve1.mul(1000).add(amountInWithFee);\n IERC20(fromToken).safeTransfer(address(pair), amountIn);\n pair.swap(amountOut, 0, to, new bytes(0));\n // TODO: Add maximum slippage?\n }\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n function _toJOE(address token, uint256 amountIn) internal returns (uint256 amountOut) {\n // X1 - X5: OK\n amountOut = _swap(token, joe, amountIn, bar);\n }\n}\n" + }, + "contracts/mocks/JoeMakerExploitMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"../JoeMaker.sol\";\n\ncontract JoeMakerExploitMock {\n JoeMaker public immutable joeMaker;\n\n constructor(address _joeMaker) public {\n joeMaker = JoeMaker(_joeMaker);\n }\n\n function convert(address token0, address token1) external {\n joeMaker.convert(token0, token1);\n }\n}\n" + }, + "contracts/TokenVesting.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.6.0;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./libraries/SafeERC20.sol\";\nimport \"./libraries/SafeMath.sol\";\n\n/**\n * @title TokenVesting\n * @dev A token holder contract that can release its token balance gradually like a\n * typical vesting scheme, with a cliff and vesting period. Optionally revocable by the\n * owner.\n */\ncontract TokenVesting is Ownable {\n // The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is\n // therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore,\n // it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a\n // cliff period of a year and a duration of four years, are safe to use.\n // solhint-disable not-rely-on-time\n\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n event TokensReleased(address token, uint256 amount);\n event TokenVestingRevoked(address token);\n\n // beneficiary of tokens after they are released\n address private _beneficiary;\n\n // Durations and timestamps are expressed in UNIX time, the same units as block.timestamp.\n uint256 private _cliff;\n uint256 private _start;\n uint256 private _duration;\n\n bool private _revocable;\n\n mapping(address => uint256) private _released;\n mapping(address => bool) private _revoked;\n\n /**\n * @dev Creates a vesting contract that vests its balance of any ERC20 token to the\n * beneficiary, gradually in a linear fashion until start + duration. By then all\n * of the balance will have vested.\n * @param beneficiary address of the beneficiary to whom vested tokens are transferred\n * @param cliffDuration duration in seconds of the cliff in which tokens will begin to vest\n * @param start the time (as Unix time) at which point vesting starts\n * @param duration duration in seconds of the period in which the tokens will vest\n * @param revocable whether the vesting is revocable or not\n */\n constructor(\n address beneficiary,\n uint256 start,\n uint256 cliffDuration,\n uint256 duration,\n bool revocable\n ) public {\n require(beneficiary != address(0), \"TokenVesting: beneficiary is the zero address\");\n // solhint-disable-next-line max-line-length\n require(cliffDuration <= duration, \"TokenVesting: cliff is longer than duration\");\n require(duration > 0, \"TokenVesting: duration is 0\");\n // solhint-disable-next-line max-line-length\n require(start.add(duration) > block.timestamp, \"TokenVesting: final time is before current time\");\n\n _beneficiary = beneficiary;\n _revocable = revocable;\n _duration = duration;\n _cliff = start.add(cliffDuration);\n _start = start;\n }\n\n /**\n * @return the beneficiary of the tokens.\n */\n function beneficiary() public view returns (address) {\n return _beneficiary;\n }\n\n /**\n * @return the cliff time of the token vesting.\n */\n function cliff() public view returns (uint256) {\n return _cliff;\n }\n\n /**\n * @return the start time of the token vesting.\n */\n function start() public view returns (uint256) {\n return _start;\n }\n\n /**\n * @return the duration of the token vesting.\n */\n function duration() public view returns (uint256) {\n return _duration;\n }\n\n /**\n * @return true if the vesting is revocable.\n */\n function revocable() public view returns (bool) {\n return _revocable;\n }\n\n /**\n * @return the amount of the token released.\n */\n function released(address token) public view returns (uint256) {\n return _released[token];\n }\n\n /**\n * @return true if the token is revoked.\n */\n function revoked(address token) public view returns (bool) {\n return _revoked[token];\n }\n\n /**\n * @notice Transfers vested tokens to beneficiary.\n * @param token ERC20 token which is being vested\n */\n function release(IERC20 token) public {\n uint256 unreleased = _releasableAmount(token);\n\n require(unreleased > 0, \"TokenVesting: no tokens are due\");\n\n _released[address(token)] = _released[address(token)].add(unreleased);\n\n token.safeTransfer(_beneficiary, unreleased);\n\n emit TokensReleased(address(token), unreleased);\n }\n\n /**\n * @notice Allows the owner to revoke the vesting. Tokens already vested\n * remain in the contract, the rest are returned to the owner.\n * @param token ERC20 token which is being vested\n */\n function revoke(IERC20 token) public onlyOwner {\n require(_revocable, \"TokenVesting: cannot revoke\");\n require(!_revoked[address(token)], \"TokenVesting: token already revoked\");\n\n uint256 balance = token.balanceOf(address(this));\n\n uint256 unreleased = _releasableAmount(token);\n uint256 refund = balance.sub(unreleased);\n\n _revoked[address(token)] = true;\n\n token.safeTransfer(owner(), refund);\n\n emit TokenVestingRevoked(address(token));\n }\n\n /**\n * @dev Calculates the amount that has already vested but hasn't been released yet.\n * @param token ERC20 token which is being vested\n */\n function _releasableAmount(IERC20 token) private view returns (uint256) {\n return _vestedAmount(token).sub(_released[address(token)]);\n }\n\n /**\n * @dev Calculates the amount that has already vested.\n * @param token ERC20 token which is being vested\n */\n function _vestedAmount(IERC20 token) private view returns (uint256) {\n uint256 currentBalance = token.balanceOf(address(this));\n uint256 totalBalance = currentBalance.add(_released[address(token)]);\n\n if (block.timestamp < _cliff) {\n return 0;\n } else if (block.timestamp >= _start.add(_duration) || _revoked[address(token)]) {\n return totalBalance;\n } else {\n return totalBalance.mul(block.timestamp.sub(_start)).div(_duration);\n }\n }\n}\n" + }, + "contracts/JoeMakerV3.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// P1 - P3: OK\npragma solidity 0.6.12;\n\nimport \"./libraries/SafeMath.sol\";\nimport \"./libraries/SafeERC20.sol\";\n\nimport \"./traderjoe/interfaces/IERC20.sol\";\nimport \"./traderjoe/interfaces/IJoePair.sol\";\nimport \"./traderjoe/interfaces/IJoeFactory.sol\";\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\n// JoeMakerV3 is MasterJoe's left hand and kinda a wizard. He can cook up Joe from pretty much anything!\n// This contract handles \"serving up\" rewards for xJoe holders by trading tokens collected from fees for Joe.\n\n// T1 - T4: OK\ncontract JoeMakerV3 is Ownable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n IJoeFactory public immutable factory;\n\n address public immutable bar;\n address private immutable joe;\n address private immutable wavax;\n uint256 public devCut = 0; // in basis points aka parts per 10,000 so 5000 is 50%, cap of 50%, default is 0\n address public devAddr;\n\n // set of addresses that can perform certain functions\n mapping(address => bool) public isAuth;\n address[] public authorized;\n bool public anyAuth = false;\n\n modifier onlyAuth() {\n require(isAuth[msg.sender] || anyAuth, \"JoeMakerV3: FORBIDDEN\");\n _;\n }\n\n // V1 - V5: OK\n mapping(address => address) internal _bridges;\n\n event SetDevAddr(address _addr);\n event SetDevCut(uint256 _amount);\n event LogBridgeSet(address indexed token, address indexed bridge);\n event LogConvert(\n address indexed server,\n address indexed token0,\n address indexed token1,\n uint256 amount0,\n uint256 amount1,\n uint256 amountJOE\n );\n\n constructor(\n address _factory,\n address _bar,\n address _joe,\n address _wavax\n ) public {\n factory = IJoeFactory(_factory);\n bar = _bar;\n joe = _joe;\n wavax = _wavax;\n devAddr = msg.sender;\n isAuth[msg.sender] = true;\n authorized.push(msg.sender);\n }\n\n // Begin Owner functions\n function addAuth(address _auth) external onlyOwner {\n isAuth[_auth] = true;\n authorized.push(_auth);\n }\n\n function revokeAuth(address _auth) external onlyOwner {\n isAuth[_auth] = false;\n }\n\n // setting anyAuth to true allows anyone to call functions protected by onlyAuth\n function setAnyAuth(bool access) external onlyOwner {\n anyAuth = access;\n }\n\n function setBridge(address token, address bridge) external onlyOwner {\n // Checks\n require(token != joe && token != wavax && token != bridge, \"JoeMakerV3: Invalid bridge\");\n\n // Effects\n _bridges[token] = bridge;\n emit LogBridgeSet(token, bridge);\n }\n\n function setDevCut(uint256 _amount) external onlyOwner {\n require(_amount <= 5000, \"setDevCut: cut too high\");\n devCut = _amount;\n\n emit SetDevCut(_amount);\n }\n\n function setDevAddr(address _addr) external onlyOwner {\n require(_addr != address(0), \"setDevAddr, address cannot be zero address\");\n devAddr = _addr;\n\n emit SetDevAddr(_addr);\n }\n\n // End owner functions\n\n function bridgeFor(address token) public view returns (address bridge) {\n bridge = _bridges[token];\n if (bridge == address(0)) {\n bridge = wavax;\n }\n }\n\n // C6: It's not a fool proof solution, but it prevents flash loans, so here it's ok to use tx.origin\n modifier onlyEOA() {\n // Try to make flash-loan exploit harder to do by only allowing externally owned addresses.\n require(msg.sender == tx.origin, \"JoeMakerV3: must use EOA\");\n _;\n }\n\n // F1 - F10: OK\n // F3: _convert is separate to save gas by only checking the 'onlyEOA' modifier once in case of convertMultiple\n // F6: There is an exploit to add lots of JOE to the bar, run convert, then remove the JOE again.\n // As the size of the JoeBar has grown, this requires large amounts of funds and isn't super profitable anymore\n // The onlyEOA modifier prevents this being done with a flash loan.\n // C1 - C24: OK\n function convert(address token0, address token1) external onlyEOA onlyAuth {\n _convert(token0, token1);\n }\n\n // F1 - F10: OK, see convert\n // C1 - C24: OK\n // C3: Loop is under control of the caller\n function convertMultiple(address[] calldata token0, address[] calldata token1) external onlyEOA onlyAuth {\n // TODO: This can be optimized a fair bit, but this is safer and simpler for now\n uint256 len = token0.length;\n for (uint256 i = 0; i < len; i++) {\n _convert(token0[i], token1[i]);\n }\n }\n\n // F1 - F10: OK\n // C1- C24: OK\n function _convert(address token0, address token1) internal {\n uint256 amount0;\n uint256 amount1;\n\n // handle case where non-LP tokens need to be converted\n if (token0 == token1) {\n amount0 = IERC20(token0).balanceOf(address(this));\n amount1 = 0;\n } else {\n IJoePair pair = IJoePair(factory.getPair(token0, token1));\n require(address(pair) != address(0), \"JoeMakerV3: Invalid pair\");\n\n IERC20(address(pair)).safeTransfer(address(pair), pair.balanceOf(address(this)));\n\n // take balance of tokens in this contract before burning the pair, incase there are already some here\n uint256 tok0bal = IERC20(token0).balanceOf(address(this));\n uint256 tok1bal = IERC20(token1).balanceOf(address(this));\n\n pair.burn(address(this));\n\n // subtract old balance of tokens from new balance\n // the return values of pair.burn cant be trusted due to transfer tax tokens\n amount0 = IERC20(token0).balanceOf(address(this)).sub(tok0bal);\n amount1 = IERC20(token1).balanceOf(address(this)).sub(tok1bal);\n }\n emit LogConvert(msg.sender, token0, token1, amount0, amount1, _convertStep(token0, token1, amount0, amount1));\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n // All safeTransfer, _swap, _toJOE, _convertStep: X1 - X5: OK\n function _convertStep(\n address token0,\n address token1,\n uint256 amount0,\n uint256 amount1\n ) internal returns (uint256 joeOut) {\n // Interactions\n if (token0 == token1) {\n uint256 amount = amount0.add(amount1);\n if (token0 == joe) {\n IERC20(joe).safeTransfer(bar, amount);\n joeOut = amount;\n } else if (token0 == wavax) {\n joeOut = _toJOE(wavax, amount);\n } else {\n address bridge = bridgeFor(token0);\n amount = _swap(token0, bridge, amount, address(this));\n joeOut = _convertStep(bridge, bridge, amount, 0);\n }\n } else if (token0 == joe) {\n // eg. JOE - AVAX\n IERC20(joe).safeTransfer(bar, amount0);\n joeOut = _toJOE(token1, amount1).add(amount0);\n } else if (token1 == joe) {\n // eg. USDT - JOE\n IERC20(joe).safeTransfer(bar, amount1);\n joeOut = _toJOE(token0, amount0).add(amount1);\n } else if (token0 == wavax) {\n // eg. AVAX - USDC\n joeOut = _toJOE(wavax, _swap(token1, wavax, amount1, address(this)).add(amount0));\n } else if (token1 == wavax) {\n // eg. USDT - AVAX\n joeOut = _toJOE(wavax, _swap(token0, wavax, amount0, address(this)).add(amount1));\n } else {\n // eg. MIC - USDT\n address bridge0 = bridgeFor(token0);\n address bridge1 = bridgeFor(token1);\n if (bridge0 == token1) {\n // eg. MIC - USDT - and bridgeFor(MIC) = USDT\n joeOut = _convertStep(bridge0, token1, _swap(token0, bridge0, amount0, address(this)), amount1);\n } else if (bridge1 == token0) {\n // eg. WBTC - DSD - and bridgeFor(DSD) = WBTC\n joeOut = _convertStep(token0, bridge1, amount0, _swap(token1, bridge1, amount1, address(this)));\n } else {\n joeOut = _convertStep(\n bridge0,\n bridge1, // eg. USDT - DSD - and bridgeFor(DSD) = WBTC\n _swap(token0, bridge0, amount0, address(this)),\n _swap(token1, bridge1, amount1, address(this))\n );\n }\n }\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n // All safeTransfer, swap: X1 - X5: OK\n function _swap(\n address fromToken,\n address toToken,\n uint256 amountIn,\n address to\n ) internal returns (uint256 amountOut) {\n // Checks\n // X1 - X5: OK\n IJoePair pair = IJoePair(factory.getPair(fromToken, toToken));\n require(address(pair) != address(0), \"JoeMakerV3: Cannot convert\");\n\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n (uint256 reserveInput, uint256 reserveOutput) = fromToken == pair.token0()\n ? (reserve0, reserve1)\n : (reserve1, reserve0);\n IERC20(fromToken).safeTransfer(address(pair), amountIn);\n uint256 amountInput = IERC20(fromToken).balanceOf(address(pair)).sub(reserveInput); // calculate amount that was transferred, this accounts for transfer taxes\n\n amountOut = getAmountOut(amountInput, reserveInput, reserveOutput);\n (uint256 amount0Out, uint256 amount1Out) = fromToken == pair.token0()\n ? (uint256(0), amountOut)\n : (amountOut, uint256(0));\n pair.swap(amount0Out, amount1Out, to, new bytes(0));\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n function _toJOE(address token, uint256 amountIn) internal returns (uint256 amountOut) {\n uint256 amount = amountIn;\n if (devCut > 0) {\n amount = amount.mul(devCut).div(10000);\n IERC20(token).safeTransfer(devAddr, amount);\n amount = amountIn.sub(amount);\n }\n amountOut = _swap(token, joe, amount, bar);\n }\n\n function getAmountOut(\n uint256 amountIn,\n uint256 reserveIn,\n uint256 reserveOut\n ) internal pure returns (uint256 amountOut) {\n require(amountIn > 0, \"JoeMakerV3: INSUFFICIENT_INPUT_AMOUNT\");\n require(reserveIn > 0 && reserveOut > 0, \"JoeMakerV3: INSUFFICIENT_LIQUIDITY\");\n uint256 amountInWithFee = amountIn.mul(997);\n uint256 numerator = amountInWithFee.mul(reserveOut);\n uint256 denominator = reserveIn.mul(1000).add(amountInWithFee);\n amountOut = numerator / denominator;\n }\n}\n" + }, + "contracts/JoeBar.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\n\n// JoeBar is the coolest bar in town. You come in with some Joe, and leave with more! The longer you stay, the more Joe you get.\n//\n// This contract handles swapping to and from xJoe, JoeSwap's staking token.\ncontract JoeBar is ERC20(\"JoeBar\", \"xJOE\") {\n using SafeMath for uint256;\n IERC20 public joe;\n\n // Define the Joe token contract\n constructor(IERC20 _joe) public {\n joe = _joe;\n }\n\n // Enter the bar. Pay some JOEs. Earn some shares.\n // Locks Joe and mints xJoe\n function enter(uint256 _amount) public {\n // Gets the amount of Joe locked in the contract\n uint256 totalJoe = joe.balanceOf(address(this));\n // Gets the amount of xJoe in existence\n uint256 totalShares = totalSupply();\n // If no xJoe exists, mint it 1:1 to the amount put in\n if (totalShares == 0 || totalJoe == 0) {\n _mint(msg.sender, _amount);\n }\n // Calculate and mint the amount of xJoe the Joe is worth. The ratio will change overtime, as xJoe is burned/minted and Joe deposited + gained from fees / withdrawn.\n else {\n uint256 what = _amount.mul(totalShares).div(totalJoe);\n _mint(msg.sender, what);\n }\n // Lock the Joe in the contract\n joe.transferFrom(msg.sender, address(this), _amount);\n }\n\n // Leave the bar. Claim back your JOEs.\n // Unlocks the staked + gained Joe and burns xJoe\n function leave(uint256 _share) public {\n // Gets the amount of xJoe in existence\n uint256 totalShares = totalSupply();\n // Calculates the amount of Joe the xJoe is worth\n uint256 what = _share.mul(joe.balanceOf(address(this))).div(totalShares);\n _burn(msg.sender, _share);\n joe.transfer(msg.sender, what);\n }\n}\n" + }, + "contracts/interfaces/IMasterChef.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\nimport \"../libraries/BoringERC20.sol\";\n\ninterface IMasterChef {\n using BoringERC20 for IERC20;\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\n }\n\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n\n function devPercent() external view returns (uint256);\n\n function treasuryPercent() external view returns (uint256);\n\n function investorPercent() external view returns (uint256);\n}\n" + }, + "contracts/JoeHatToken.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.6.2;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol\";\n\ncontract JoeHatToken is ERC20Burnable {\n /**\n * @dev Mints `initialSupply` amount of token and transfers them to `owner`.\n *\n * See {ERC20-constructor}.\n */\n constructor(address owner) public ERC20(\"Joe Hat Token\", \"HAT\") {\n uint256 initialSupply = 150e18;\n _mint(owner, initialSupply);\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../../utils/Context.sol\";\nimport \"./ERC20.sol\";\n\n/**\n * @dev Extension of {ERC20} that allows token holders to destroy both their own\n * tokens and those that they have an allowance for, in a way that can be\n * recognized off-chain (via event analysis).\n */\nabstract contract ERC20Burnable is Context, ERC20 {\n using SafeMath for uint256;\n\n /**\n * @dev Destroys `amount` tokens from the caller.\n *\n * See {ERC20-_burn}.\n */\n function burn(uint256 amount) public virtual {\n _burn(_msgSender(), amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, deducting from the caller's\n * allowance.\n *\n * See {ERC20-_burn} and {ERC20-allowance}.\n *\n * Requirements:\n *\n * - the caller must have allowance for ``accounts``'s tokens of at least\n * `amount`.\n */\n function burnFrom(address account, uint256 amount) public virtual {\n uint256 decreasedAllowance = allowance(account, _msgSender()).sub(amount, \"ERC20: burn amount exceeds allowance\");\n\n _approve(account, _msgSender(), decreasedAllowance);\n _burn(account, amount);\n }\n}\n" + }, + "contracts/traderjoe/JoeFactory.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\nimport \"./interfaces/IJoeFactory.sol\";\nimport \"./JoePair.sol\";\n\ncontract JoeFactory is IJoeFactory {\n address public override feeTo;\n address public override feeToSetter;\n address public override migrator;\n\n mapping(address => mapping(address => address)) public override getPair;\n address[] public override allPairs;\n\n event PairCreated(address indexed token0, address indexed token1, address pair, uint256);\n\n constructor(address _feeToSetter) public {\n feeToSetter = _feeToSetter;\n }\n\n function allPairsLength() external view override returns (uint256) {\n return allPairs.length;\n }\n\n function pairCodeHash() external pure returns (bytes32) {\n return keccak256(type(JoePair).creationCode);\n }\n\n function createPair(address tokenA, address tokenB) external override returns (address pair) {\n require(tokenA != tokenB, \"Joe: IDENTICAL_ADDRESSES\");\n (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);\n require(token0 != address(0), \"Joe: ZERO_ADDRESS\");\n require(getPair[token0][token1] == address(0), \"Joe: PAIR_EXISTS\"); // single check is sufficient\n bytes memory bytecode = type(JoePair).creationCode;\n bytes32 salt = keccak256(abi.encodePacked(token0, token1));\n assembly {\n pair := create2(0, add(bytecode, 32), mload(bytecode), salt)\n }\n JoePair(pair).initialize(token0, token1);\n getPair[token0][token1] = pair;\n getPair[token1][token0] = pair; // populate mapping in the reverse direction\n allPairs.push(pair);\n emit PairCreated(token0, token1, pair, allPairs.length);\n }\n\n function setFeeTo(address _feeTo) external override {\n require(msg.sender == feeToSetter, \"Joe: FORBIDDEN\");\n feeTo = _feeTo;\n }\n\n function setMigrator(address _migrator) external override {\n require(msg.sender == feeToSetter, \"Joe: FORBIDDEN\");\n migrator = _migrator;\n }\n\n function setFeeToSetter(address _feeToSetter) external override {\n require(msg.sender == feeToSetter, \"Joe: FORBIDDEN\");\n feeToSetter = _feeToSetter;\n }\n}\n" + } + }, + "settings": { + "optimizer": { + "enabled": true, + "runs": 200 + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata", + "devdoc", + "userdoc", + "storageLayout", + "evm.gasEstimates" + ], + "": [ + "ast" + ] + } + }, + "metadata": { + "useLiteralContent": true + }, + "libraries": { + "": { + "__CACHE_BREAKER__": "0x00000000d41867734bbee4c6863d9255b2b06ac1" + } + } + } +} \ No newline at end of file diff --git a/deployments/rinkeby/FarmLensV2.json b/deployments/rinkeby/FarmLensV2.json index 8c9ea8b4..2f0e3be0 100644 --- a/deployments/rinkeby/FarmLensV2.json +++ b/deployments/rinkeby/FarmLensV2.json @@ -1,5 +1,5 @@ { - "address": "0x8A6FA314799b5E5553Cbce7fab3d9EAdEf5ee85a", + "address": "0xBd483b62612a859C5E66f8B7CFb6587fD7657B88", "abi": [ { "inputs": [ @@ -371,27 +371,42 @@ }, { "internalType": "uint256", - "name": "userLp", + "name": "baseApr", "type": "uint256" }, { "internalType": "uint256", - "name": "userPendingJoe", + "name": "averageBoostedApr", "type": "uint256" }, { "internalType": "uint256", - "name": "baseAPR", + "name": "veJoeShareBp", "type": "uint256" }, { "internalType": "uint256", - "name": "boostedAPR", + "name": "joePriceUsd", "type": "uint256" }, { "internalType": "uint256", - "name": "boostFactor", + "name": "userLp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "userPendingJoe", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "userBoostedApr", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "userFactorShare", "type": "uint256" } ], @@ -510,27 +525,42 @@ }, { "internalType": "uint256", - "name": "userLp", + "name": "baseApr", "type": "uint256" }, { "internalType": "uint256", - "name": "userPendingJoe", + "name": "averageBoostedApr", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "veJoeShareBp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "joePriceUsd", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "userLp", "type": "uint256" }, { "internalType": "uint256", - "name": "baseAPR", + "name": "userPendingJoe", "type": "uint256" }, { "internalType": "uint256", - "name": "boostedAPR", + "name": "userBoostedApr", "type": "uint256" }, { "internalType": "uint256", - "name": "boostFactor", + "name": "userFactorShare", "type": "uint256" } ], @@ -750,19 +780,19 @@ "type": "function" } ], - "transactionHash": "0x527ef4ffc28caa493f6854ea3b202f08771fbb00f5a2b63a63780f9e908c1571", + "transactionHash": "0x237710834fa0ad7b032c3dffb34a7e4e2cf38d48bc9964d311e7662814b3bfdb", "receipt": { "to": null, "from": "0x2bC66ec6fEF31e670cc9196c6922CEbd3D96aDad", - "contractAddress": "0x8A6FA314799b5E5553Cbce7fab3d9EAdEf5ee85a", - "transactionIndex": 3, - "gasUsed": "2667132", + "contractAddress": "0xBd483b62612a859C5E66f8B7CFb6587fD7657B88", + "transactionIndex": 0, + "gasUsed": "2738890", "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "blockHash": "0xbb6ec7611818901341c9409bb5085d11be673f3571cb614693247bf9fca4cda9", - "transactionHash": "0x527ef4ffc28caa493f6854ea3b202f08771fbb00f5a2b63a63780f9e908c1571", + "blockHash": "0xc2dcc65d32f93aca76ee7421d13bbcb44d90c5f620d7c69fab1751b6c827252e", + "transactionHash": "0x237710834fa0ad7b032c3dffb34a7e4e2cf38d48bc9964d311e7662814b3bfdb", "logs": [], - "blockNumber": 10382914, - "cumulativeGasUsed": "3651824", + "blockNumber": 10389086, + "cumulativeGasUsed": "2738890", "status": 1, "byzantium": true }, @@ -777,11 +807,11 @@ "0xEedf119022F1Bb5F63676BbE855c82151B7198AF", "0x460d978831afd5Af99738E060C3ad8a76e592beA" ], - "numDeployments": 1, - "solcInputHash": "8e2f9a48c0098ed6f143dc231263c002", - "metadata": "{\"compiler\":{\"version\":\"0.6.12+commit.27d51765\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_joe\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"_wavax\",\"type\":\"address\"},{\"internalType\":\"contract IJoePair\",\"name\":\"_wavaxUsdte\",\"type\":\"address\"},{\"internalType\":\"contract IJoePair\",\"name\":\"_wavaxUsdce\",\"type\":\"address\"},{\"internalType\":\"contract IJoePair\",\"name\":\"_wavaxUsdc\",\"type\":\"address\"},{\"internalType\":\"contract IJoeFactory\",\"name\":\"_joeFactory\",\"type\":\"address\"},{\"internalType\":\"contract IMasterChef\",\"name\":\"_chefv2\",\"type\":\"address\"},{\"internalType\":\"contract IMasterChef\",\"name\":\"_chefv3\",\"type\":\"address\"},{\"internalType\":\"contract IBoostedMasterchef\",\"name\":\"_bmcj\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"bmcj\",\"outputs\":[{\"internalType\":\"contract IBoostedMasterchef\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"chefv2\",\"outputs\":[{\"internalType\":\"contract IMasterChef\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"chefv3\",\"outputs\":[{\"internalType\":\"contract IMasterChef\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPidsV2\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPidsV3\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPidsBMCJ\",\"type\":\"uint256[]\"},{\"internalType\":\"address\",\"name\":\"user\",\"type\":\"address\"}],\"name\":\"getAllFarmData\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"avaxPriceUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePriceUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAllocChefV2\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAllocChefV3\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAllocBMCJ\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePerSecChefV2\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePerSecChefV3\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePerSecBMCJ\",\"type\":\"uint256\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfo[]\",\"name\":\"farmInfosV2\",\"type\":\"tuple[]\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfo[]\",\"name\":\"farmInfosV3\",\"type\":\"tuple[]\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userLp\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userPendingJoe\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"baseAPR\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"boostedAPR\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"boostFactor\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfoBMCJ[]\",\"name\":\"farmInfosBMCJ\",\"type\":\"tuple[]\"}],\"internalType\":\"struct FarmLensV2.AllFarmData\",\"name\":\"\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getAvaxPrice\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"contract IBoostedMasterchef\",\"name\":\"chef\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"user\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPids\",\"type\":\"uint256[]\"}],\"name\":\"getBMCJFarmInfos\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userLp\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userPendingJoe\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"baseAPR\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"boostedAPR\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"boostFactor\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfoBMCJ[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"}],\"name\":\"getDerivedAvaxPriceOfToken\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"contract IMasterChef\",\"name\":\"chef\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPids\",\"type\":\"uint256[]\"}],\"name\":\"getMCFarmInfos\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfo[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"}],\"name\":\"getTokenPrice\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"joe\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"joeFactory\",\"outputs\":[{\"internalType\":\"contract IJoeFactory\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavax\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavaxUsdc\",\"outputs\":[{\"internalType\":\"contract IJoePair\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavaxUsdce\",\"outputs\":[{\"internalType\":\"contract IJoePair\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavaxUsdte\",\"outputs\":[{\"internalType\":\"contract IJoePair\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"getAllFarmData(uint256[],uint256[],uint256[],address)\":{\"params\":{\"user\":\"The address of the user, if address(0), returns global info\",\"whitelistedPidsBMCJ\":\"Array of all ids of pools that are whitelisted in BMCJ\",\"whitelistedPidsV2\":\"Array of all ids of pools that are whitelisted in chefV2\",\"whitelistedPidsV3\":\"Array of all ids of pools that are whitelisted in chefV3\"},\"returns\":{\"_0\":\"AllFarmData The information of all the whitelisted farms of MCV2, MCV3 and BMCJ\"}},\"getAvaxPrice()\":{\"returns\":{\"_0\":\"uint256 the avax price, scaled to 18 decimals\"}},\"getBMCJFarmInfos(address,address,uint256[])\":{\"params\":{\"chef\":\"The address of the MasterChef\",\"user\":\"The address of the user, if address(0), returns global info\",\"whitelistedPids\":\"Array of all ids of pools that are whitelisted and valid to have their farm data returned\"},\"returns\":{\"_0\":\"FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\"}},\"getDerivedAvaxPriceOfToken(address)\":{\"params\":{\"token\":\"The address of the token\"},\"returns\":{\"_0\":\"uint256 the token derived price, scaled to 18 decimals\"}},\"getMCFarmInfos(address,uint256[])\":{\"params\":{\"chef\":\"The address of the MasterChef\",\"whitelistedPids\":\"Array of all ids of pools that are whitelisted and valid to have their farm data returned\"},\"returns\":{\"_0\":\"FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\"}},\"getTokenPrice(address)\":{\"params\":{\"token\":\"The address of the token\"},\"returns\":{\"_0\":\"uint256 the Usd price of token, scaled to 18 decimals\"}}},\"stateVariables\":{\"SEC_PER_YEAR\":{\"details\":\"365 * 86400, hard coding it for gas optimisation\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"getAllFarmData(uint256[],uint256[],uint256[],address)\":{\"notice\":\"Get all data needed for useFarms hook.\"},\"getAvaxPrice()\":{\"notice\":\"Returns the price of avax in Usd\"},\"getBMCJFarmInfos(address,address,uint256[])\":{\"notice\":\"Returns the farm pairs data for BoostedMasterChefJoe\"},\"getDerivedAvaxPriceOfToken(address)\":{\"notice\":\"Returns the derived price of token, it needs to be paired with wavax\"},\"getMCFarmInfos(address,uint256[])\":{\"notice\":\"Returns the farm pairs data for MCV2 and MCV3\"},\"getTokenPrice(address)\":{\"notice\":\"Returns the Usd price of token, it needs to be paired with wavax\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"contracts/traderjoe/FarmLensV2.sol\":\"FarmLensV2\"},\"evmVersion\":\"istanbul\",\"libraries\":{\"__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"contracts/interfaces/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\n\\ninterface IERC20 {\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address account) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 amount) external returns (bool);\\n\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n\\n // EIP 2612\\n function permit(\\n address owner,\\n address spender,\\n uint256 value,\\n uint256 deadline,\\n uint8 v,\\n bytes32 r,\\n bytes32 s\\n ) external;\\n}\\n\",\"keccak256\":\"0xa3fb82796e80f566a5c47f9a1f2ade7de7f390dfdc06bea5375112b9f9314f40\",\"license\":\"MIT\"},\"contracts/libraries/SafeERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\n\\nimport \\\"../interfaces/IERC20.sol\\\";\\n\\nlibrary SafeERC20 {\\n function safeSymbol(IERC20 token) internal view returns (string memory) {\\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x95d89b41));\\n return success && data.length > 0 ? abi.decode(data, (string)) : \\\"???\\\";\\n }\\n\\n function safeName(IERC20 token) internal view returns (string memory) {\\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x06fdde03));\\n return success && data.length > 0 ? abi.decode(data, (string)) : \\\"???\\\";\\n }\\n\\n function safeDecimals(IERC20 token) internal view returns (uint8) {\\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x313ce567));\\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\\n }\\n\\n function safeTransfer(\\n IERC20 token,\\n address to,\\n uint256 amount\\n ) internal {\\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(0xa9059cbb, to, amount));\\n require(success && (data.length == 0 || abi.decode(data, (bool))), \\\"SafeERC20: Transfer failed\\\");\\n }\\n\\n function safeTransferFrom(\\n IERC20 token,\\n address from,\\n uint256 amount\\n ) internal {\\n (bool success, bytes memory data) = address(token).call(\\n abi.encodeWithSelector(0x23b872dd, from, address(this), amount)\\n );\\n require(success && (data.length == 0 || abi.decode(data, (bool))), \\\"SafeERC20: TransferFrom failed\\\");\\n }\\n}\\n\",\"keccak256\":\"0xdd77ee6d503b5396208d64e811ee89ca55389c62071003cc223f4ea0029c10ac\",\"license\":\"MIT\"},\"contracts/libraries/SafeMath.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\n\\n// a library for performing overflow-safe math, updated with awesomeness from of DappHub (https://github.com/dapphub/ds-math)\\nlibrary SafeMath {\\n function add(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require((c = a + b) >= b, \\\"SafeMath: Add Overflow\\\");\\n }\\n\\n function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require((c = a - b) <= a, \\\"SafeMath: Underflow\\\");\\n }\\n\\n function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require(b == 0 || (c = a * b) / b == a, \\\"SafeMath: Mul Overflow\\\");\\n }\\n\\n function div(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require(b > 0, \\\"SafeMath: Div by Zero\\\");\\n c = a / b;\\n }\\n\\n function to128(uint256 a) internal pure returns (uint128 c) {\\n require(a <= uint128(-1), \\\"SafeMath: uint128 Overflow\\\");\\n c = uint128(a);\\n }\\n}\\n\\nlibrary SafeMath128 {\\n function add(uint128 a, uint128 b) internal pure returns (uint128 c) {\\n require((c = a + b) >= b, \\\"SafeMath: Add Overflow\\\");\\n }\\n\\n function sub(uint128 a, uint128 b) internal pure returns (uint128 c) {\\n require((c = a - b) <= a, \\\"SafeMath: Underflow\\\");\\n }\\n}\\n\",\"keccak256\":\"0x8b8dcb649a07667a9a97c050a374a82389e7a19254abaebedf399c00619042a8\",\"license\":\"MIT\"},\"contracts/traderjoe/FarmLensV2.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\npragma experimental ABIEncoderV2;\\nimport \\\"../libraries/SafeMath.sol\\\";\\nimport \\\"../libraries/SafeERC20.sol\\\";\\n\\nimport \\\"./interfaces/IERC20.sol\\\";\\nimport \\\"./interfaces/IJoeERC20.sol\\\";\\nimport \\\"./interfaces/IJoePair.sol\\\";\\nimport \\\"./interfaces/IJoeFactory.sol\\\";\\n\\ninterface IMasterChef {\\n struct PoolInfo {\\n IJoeERC20 lpToken; // Address of LP token contract.\\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\\n }\\n\\n function poolLength() external view returns (uint256);\\n\\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\\n\\n function totalAllocPoint() external view returns (uint256);\\n\\n function joePerSec() external view returns (uint256);\\n}\\n\\ninterface IBoostedMasterchef {\\n struct UserInfo {\\n uint256 amount;\\n uint256 rewardDebt;\\n uint256 factor;\\n }\\n\\n struct PoolInfo {\\n IERC20 lpToken;\\n uint96 allocPoint;\\n uint256 accJoePerShare;\\n uint256 accJoePerFactorPerShare;\\n uint64 lastRewardTimestamp;\\n address rewarder;\\n uint32 veJoeShareBp;\\n uint256 totalFactor;\\n uint256 totalLpSupply;\\n }\\n\\n function userInfo(uint256 _pid, address user) external view returns (UserInfo memory);\\n \\n function pendingTokens(uint256 _pid, address user) external view returns (uint256, address, string memory, uint256);\\n\\n function poolLength() external view returns (uint256);\\n\\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\\n\\n function totalAllocPoint() external view returns (uint256);\\n\\n function joePerSec() external view returns (uint256);\\n}\\n\\ncontract FarmLensV2 {\\n using SafeMath for uint256;\\n using SafeERC20 for IERC20;\\n\\n struct FarmInfo {\\n uint256 id;\\n uint256 allocPoint;\\n address lpAddress;\\n address token0Address;\\n address token1Address;\\n string token0Symbol;\\n string token1Symbol;\\n uint256 reserveUsd;\\n uint256 totalSupplyScaled;\\n address chefAddress;\\n uint256 chefBalanceScaled;\\n uint256 chefTotalAlloc;\\n uint256 chefJoePerSec;\\n }\\n\\n struct FarmInfoBMCJ {\\n uint256 id;\\n uint256 allocPoint;\\n address lpAddress;\\n address token0Address;\\n address token1Address;\\n string token0Symbol;\\n string token1Symbol;\\n uint256 reserveUsd;\\n uint256 totalSupplyScaled;\\n address chefAddress;\\n uint256 chefBalanceScaled;\\n uint256 chefTotalAlloc;\\n uint256 chefJoePerSec;\\n uint256 userLp;\\n uint256 userPendingJoe;\\n uint256 baseAPR;\\n uint256 boostedAPR;\\n uint256 boostFactor;\\n }\\n\\n struct AllFarmData {\\n uint256 avaxPriceUsd;\\n uint256 joePriceUsd;\\n uint256 totalAllocChefV2;\\n uint256 totalAllocChefV3;\\n uint256 totalAllocBMCJ;\\n uint256 joePerSecChefV2;\\n uint256 joePerSecChefV3;\\n uint256 joePerSecBMCJ;\\n FarmInfo[] farmInfosV2;\\n FarmInfo[] farmInfosV3;\\n FarmInfoBMCJ[] farmInfosBMCJ;\\n }\\n\\n struct GlobalInfo {\\n address chef;\\n uint256 totalAlloc;\\n uint256 joePerSec;\\n }\\n\\n /// @dev 365 * 86400, hard coding it for gas optimisation\\n uint256 private constant SEC_PER_YEAR = 31536000;\\n uint256 private constant BP_PRECISION = 10_000;\\n uint256 private constant PRECISION = 1e18;\\n\\n address public immutable joe; // 0x6e84a6216eA6dACC71eE8E6b0a5B7322EEbC0fDd;\\n address public immutable wavax; // 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7;\\n IJoePair public immutable wavaxUsdte; // 0xeD8CBD9F0cE3C6986b22002F03c6475CEb7a6256\\n IJoePair public immutable wavaxUsdce; // 0xA389f9430876455C36478DeEa9769B7Ca4E3DDB1\\n IJoePair public immutable wavaxUsdc; // 0xf4003f4efbe8691b60249e6afbd307abe7758adb\\n IJoeFactory public immutable joeFactory; // 0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10\\n IMasterChef public immutable chefv2; // 0xd6a4F121CA35509aF06A0Be99093d08462f53052\\n IMasterChef public immutable chefv3; // 0x188bED1968b795d5c9022F6a0bb5931Ac4c18F00\\n IBoostedMasterchef public immutable bmcj; // Not deployed yet\\n bool private immutable isWavaxToken1InWavaxUsdte;\\n bool private immutable isWavaxToken1InWavaxUsdce;\\n bool private immutable isWavaxToken1InWavaxUsdc;\\n\\n constructor(\\n address _joe,\\n address _wavax,\\n IJoePair _wavaxUsdte,\\n IJoePair _wavaxUsdce,\\n IJoePair _wavaxUsdc,\\n IJoeFactory _joeFactory,\\n IMasterChef _chefv2,\\n IMasterChef _chefv3,\\n IBoostedMasterchef _bmcj\\n ) public {\\n joe = _joe;\\n wavax = _wavax;\\n wavaxUsdte = _wavaxUsdte;\\n wavaxUsdce = _wavaxUsdce;\\n wavaxUsdc = _wavaxUsdc;\\n joeFactory = _joeFactory;\\n chefv2 = _chefv2;\\n chefv3 = _chefv3;\\n bmcj = _bmcj;\\n\\n isWavaxToken1InWavaxUsdte = _wavaxUsdte.token1() == _wavax;\\n isWavaxToken1InWavaxUsdce = _wavaxUsdce.token1() == _wavax;\\n isWavaxToken1InWavaxUsdc = _wavaxUsdc.token1() == _wavax;\\n }\\n\\n /// @notice Returns the price of avax in Usd\\n /// @return uint256 the avax price, scaled to 18 decimals\\n function getAvaxPrice() external view returns (uint256) {\\n return _getAvaxPrice();\\n }\\n\\n /// @notice Returns the derived price of token, it needs to be paired with wavax\\n /// @param token The address of the token\\n /// @return uint256 the token derived price, scaled to 18 decimals\\n function getDerivedAvaxPriceOfToken(address token) external view returns (uint256) {\\n return _getDerivedAvaxPriceOfToken(token);\\n }\\n\\n /// @notice Returns the Usd price of token, it needs to be paired with wavax\\n /// @param token The address of the token\\n /// @return uint256 the Usd price of token, scaled to 18 decimals\\n function getTokenPrice(address token) external view returns (uint256) {\\n return _getDerivedAvaxPriceOfToken(token).mul(_getAvaxPrice()) / 1e18;\\n }\\n\\n /// @notice Returns the farm pairs data for MCV2 and MCV3\\n /// @param chef The address of the MasterChef\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\\n function getMCFarmInfos(IMasterChef chef, uint256[] calldata whitelistedPids)\\n external\\n view\\n returns (FarmInfo[] memory)\\n {\\n require(chef == chefv2 || chef == chefv3, \\\"FarmLensV2: only for MCV2 and MCV3\\\");\\n\\n uint256 avaxPrice = _getAvaxPrice();\\n return _getMCFarmInfos(chef, avaxPrice, whitelistedPids);\\n }\\n\\n /// @notice Returns the farm pairs data for BoostedMasterChefJoe\\n /// @param chef The address of the MasterChef\\n /// @param user The address of the user, if address(0), returns global info\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\\n function getBMCJFarmInfos(\\n IBoostedMasterchef chef,\\n address user,\\n uint256[] calldata whitelistedPids\\n ) external view returns (FarmInfoBMCJ[] memory) {\\n require(chef == bmcj, \\\"FarmLensV2: Only for BMCJ\\\");\\n\\n uint256 avaxPrice = _getAvaxPrice();\\n uint256 joePrice = _getDerivedAvaxPriceOfToken(joe).mul(avaxPrice) / PRECISION;\\n return _getBMCJFarmInfos(avaxPrice, joePrice, user, whitelistedPids);\\n }\\n\\n /// @notice Get all data needed for useFarms hook.\\n /// @param whitelistedPidsV2 Array of all ids of pools that are whitelisted in chefV2\\n /// @param whitelistedPidsV3 Array of all ids of pools that are whitelisted in chefV3\\n /// @param whitelistedPidsBMCJ Array of all ids of pools that are whitelisted in BMCJ\\n /// @param user The address of the user, if address(0), returns global info\\n /// @return AllFarmData The information of all the whitelisted farms of MCV2, MCV3 and BMCJ\\n function getAllFarmData(\\n uint256[] calldata whitelistedPidsV2,\\n uint256[] calldata whitelistedPidsV3,\\n uint256[] calldata whitelistedPidsBMCJ,\\n address user\\n ) external view returns (AllFarmData memory) {\\n AllFarmData memory allFarmData;\\n\\n uint256 avaxPrice = _getAvaxPrice();\\n uint256 joePrice = _getDerivedAvaxPriceOfToken(joe).mul(avaxPrice) / PRECISION;\\n\\n allFarmData.avaxPriceUsd = avaxPrice;\\n allFarmData.joePriceUsd = joePrice;\\n\\n allFarmData.totalAllocChefV2 = chefv2.totalAllocPoint();\\n allFarmData.joePerSecChefV2 = chefv2.joePerSec();\\n\\n allFarmData.totalAllocChefV3 = chefv3.totalAllocPoint();\\n allFarmData.joePerSecChefV3 = chefv3.joePerSec();\\n\\n allFarmData.totalAllocBMCJ = bmcj.totalAllocPoint();\\n allFarmData.joePerSecBMCJ = bmcj.joePerSec();\\n\\n allFarmData.farmInfosV2 = _getMCFarmInfos(chefv2, avaxPrice, whitelistedPidsV2);\\n allFarmData.farmInfosV3 = _getMCFarmInfos(chefv3, avaxPrice, whitelistedPidsV3);\\n allFarmData.farmInfosBMCJ = _getBMCJFarmInfos(avaxPrice, joePrice, user, whitelistedPidsBMCJ);\\n\\n return allFarmData;\\n }\\n\\n /// @notice Returns the price of avax in Usd internally\\n /// @return uint256 the avax price, scaled to 18 decimals\\n function _getAvaxPrice() private view returns (uint256) {\\n return\\n _getDerivedTokenPriceOfPair(wavaxUsdte, isWavaxToken1InWavaxUsdte)\\n .add(_getDerivedTokenPriceOfPair(wavaxUsdce, isWavaxToken1InWavaxUsdce))\\n .add(_getDerivedTokenPriceOfPair(wavaxUsdc, isWavaxToken1InWavaxUsdc)) / 3;\\n }\\n\\n /// @notice Returns the derived price of token in the other token\\n /// @param pair The address of the pair\\n /// @param derivedtoken0 If price should be derived from token0 if true, or token1 if false\\n /// @return uint256 the derived price, scaled to 18 decimals\\n function _getDerivedTokenPriceOfPair(IJoePair pair, bool derivedtoken0) private view returns (uint256) {\\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\\n uint256 decimals0 = IERC20(pair.token0()).safeDecimals();\\n uint256 decimals1 = IERC20(pair.token1()).safeDecimals();\\n\\n if (derivedtoken0) {\\n return _scaleTo(reserve0, decimals1.add(18).sub(decimals0)).div(reserve1);\\n } else {\\n return _scaleTo(reserve1, decimals0.add(18).sub(decimals1)).div(reserve0);\\n }\\n }\\n\\n /// @notice Returns the derived price of token, it needs to be paired with wavax\\n /// @param token The address of the token\\n /// @return uint256 the token derived price, scaled to 18 decimals\\n function _getDerivedAvaxPriceOfToken(address token) private view returns (uint256) {\\n if (token == wavax) {\\n return PRECISION;\\n }\\n IJoePair pair = IJoePair(joeFactory.getPair(token, wavax));\\n if (address(pair) == address(0)) {\\n return 0;\\n }\\n // instead of testing wavax == pair.token0(), we do the opposite to save gas\\n return _getDerivedTokenPriceOfPair(pair, token == pair.token1());\\n }\\n\\n /// @notice Returns the amount scaled to decimals\\n /// @param amount The amount\\n /// @param decimals The decimals to scale `amount`\\n /// @return uint256 The amount scaled to decimals\\n function _scaleTo(uint256 amount, uint256 decimals) private pure returns (uint256) {\\n if (decimals == 0) return amount;\\n return amount.mul(10**decimals);\\n }\\n\\n /// @notice Returns the derived avax liquidity, at least one of the token needs to be paired with wavax\\n /// @param pair The address of the pair\\n /// @return uint256 the derived price of pair's liquidity, scaled to 18 decimals\\n function _getDerivedAvaxLiquidityOfPair(IJoePair pair) private view returns (uint256) {\\n address _wavax = wavax;\\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\\n IERC20 token0 = IERC20(pair.token0());\\n IERC20 token1 = IERC20(pair.token1());\\n uint256 decimals0 = token0.safeDecimals();\\n uint256 decimals1 = token1.safeDecimals();\\n\\n reserve0 = _scaleTo(reserve0, uint256(18).sub(decimals0));\\n reserve1 = _scaleTo(reserve1, uint256(18).sub(decimals1));\\n\\n uint256 token0DerivedAvaxPrice;\\n uint256 token1DerivedAvaxPrice;\\n if (address(token0) == _wavax) {\\n token0DerivedAvaxPrice = PRECISION;\\n token1DerivedAvaxPrice = _getDerivedTokenPriceOfPair(pair, true);\\n } else if (address(token1) == _wavax) {\\n token0DerivedAvaxPrice = _getDerivedTokenPriceOfPair(pair, false);\\n token1DerivedAvaxPrice = PRECISION;\\n } else {\\n token0DerivedAvaxPrice = _getDerivedAvaxPriceOfToken(address(token0));\\n token1DerivedAvaxPrice = _getDerivedAvaxPriceOfToken(address(token1));\\n // If one token isn't paired with wavax, then we hope that the second one is.\\n // E.g, TOKEN/UsdC, token might not be paired with wavax, but UsdC is.\\n // If both aren't paired with wavax, return 0\\n if (token0DerivedAvaxPrice == 0) return reserve1.mul(token1DerivedAvaxPrice).mul(2) / PRECISION;\\n if (token1DerivedAvaxPrice == 0) return reserve0.mul(token0DerivedAvaxPrice).mul(2) / PRECISION;\\n }\\n return reserve0.mul(token0DerivedAvaxPrice).add(reserve1.mul(token1DerivedAvaxPrice)) / PRECISION;\\n }\\n\\n /// @notice Private function to return the farm pairs data for a given MasterChef (V2 or V3)\\n /// @param chef The address of the MasterChef\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\\n function _getMCFarmInfos(\\n IMasterChef chef,\\n uint256 avaxPrice,\\n uint256[] calldata whitelistedPids\\n ) private view returns (FarmInfo[] memory) {\\n uint256 whitelistLength = whitelistedPids.length;\\n FarmInfo[] memory farmInfos = new FarmInfo[](whitelistLength);\\n\\n uint256 chefTotalAlloc = chef.totalAllocPoint();\\n uint256 chefJoePerSec = chef.joePerSec();\\n\\n for (uint256 i; i < whitelistLength; i++) {\\n uint256 pid = whitelistedPids[i];\\n IMasterChef.PoolInfo memory pool = chef.poolInfo(pid);\\n\\n farmInfos[i] = _getMCFarmInfo(\\n chef,\\n avaxPrice,\\n pid,\\n IJoePair(address(pool.lpToken)),\\n pool.allocPoint,\\n chefTotalAlloc,\\n chefJoePerSec\\n );\\n }\\n\\n return farmInfos;\\n }\\n\\n /// @notice Helper function to return the farm info of a given pool\\n /// @param chef The address of the MasterChef\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param pid The pid of the pool\\n /// @param lpToken The lpToken of the pool\\n /// @param allocPoint The allocPoint of the pool\\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\\n function _getMCFarmInfo(\\n IMasterChef chef,\\n uint256 avaxPrice,\\n uint256 pid,\\n IJoePair lpToken,\\n uint256 allocPoint,\\n uint256 totalAllocPoint,\\n uint256 chefJoePerSec\\n ) private view returns (FarmInfo memory) {\\n uint256 decimals = lpToken.decimals();\\n uint256 totalSupplyScaled = _scaleTo(lpToken.totalSupply(), 18 - decimals);\\n uint256 chefBalanceScaled = _scaleTo(lpToken.balanceOf(address(chef)), 18 - decimals);\\n uint256 reserveUsd = _getDerivedAvaxLiquidityOfPair(lpToken).mul(avaxPrice) / PRECISION;\\n IERC20 token0 = IERC20(lpToken.token0());\\n IERC20 token1 = IERC20(lpToken.token1());\\n\\n return\\n FarmInfo({\\n id: pid,\\n allocPoint: allocPoint,\\n lpAddress: address(lpToken),\\n token0Address: address(token0),\\n token1Address: address(token1),\\n token0Symbol: token0.safeSymbol(),\\n token1Symbol: token1.safeSymbol(),\\n reserveUsd: reserveUsd,\\n totalSupplyScaled: totalSupplyScaled,\\n chefBalanceScaled: chefBalanceScaled,\\n chefAddress: address(chef),\\n chefTotalAlloc: totalAllocPoint,\\n chefJoePerSec: chefJoePerSec\\n });\\n }\\n\\n /// @notice Private function to return the farm pairs data for boostedMasterChef\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param joePrice The joe price as a parameter to save gas\\n /// @param user The address of the user, if address(0), returns global info\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\\n function _getBMCJFarmInfos(\\n uint256 avaxPrice,\\n uint256 joePrice,\\n address user,\\n uint256[] calldata whitelistedPids\\n ) private view returns (FarmInfoBMCJ[] memory) {\\n GlobalInfo memory globalInfo = GlobalInfo(address(bmcj), bmcj.totalAllocPoint(), bmcj.joePerSec());\\n\\n uint256 whitelistLength = whitelistedPids.length;\\n FarmInfoBMCJ[] memory farmInfos = new FarmInfoBMCJ[](whitelistLength);\\n\\n for (uint256 i; i < whitelistLength; i++) {\\n uint256 pid = whitelistedPids[i];\\n IBoostedMasterchef.PoolInfo memory pool = IBoostedMasterchef(globalInfo.chef).poolInfo(pid);\\n IBoostedMasterchef.UserInfo memory userInfo;\\n userInfo = IBoostedMasterchef(globalInfo.chef).userInfo(pid, user);\\n\\n farmInfos[i].id = pid;\\n farmInfos[i].chefAddress = globalInfo.chef;\\n farmInfos[i].chefTotalAlloc = globalInfo.totalAlloc;\\n farmInfos[i].chefJoePerSec = globalInfo.joePerSec;\\n _getBMCJFarmInfo(\\n avaxPrice,\\n globalInfo.joePerSec.mul(joePrice) / PRECISION,\\n user,\\n farmInfos[i],\\n pool,\\n userInfo\\n );\\n }\\n\\n return farmInfos;\\n }\\n\\n /// @notice Helper function to return the farm info of a given pool of BMCJ\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param UsdPerSec The Usd per sec emitted to BMCJ\\n /// @param userAddress The address of the user\\n /// @param farmInfo The farmInfo of that pool\\n /// @param user The user information\\n function _getBMCJFarmInfo(\\n uint256 avaxPrice,\\n uint256 UsdPerSec,\\n address userAddress,\\n FarmInfoBMCJ memory farmInfo,\\n IBoostedMasterchef.PoolInfo memory pool,\\n IBoostedMasterchef.UserInfo memory user\\n ) private view {\\n {\\n IJoePair lpToken = IJoePair(address(pool.lpToken));\\n IERC20 token0 = IERC20(lpToken.token0());\\n IERC20 token1 = IERC20(lpToken.token1());\\n\\n farmInfo.allocPoint = pool.allocPoint;\\n farmInfo.lpAddress = address(lpToken);\\n farmInfo.token0Address = address(token0);\\n farmInfo.token1Address = address(token1);\\n farmInfo.token0Symbol = token0.safeSymbol();\\n farmInfo.token1Symbol = token1.safeSymbol();\\n farmInfo.reserveUsd = _getDerivedAvaxLiquidityOfPair(lpToken).mul(avaxPrice) / PRECISION;\\n // LP is in 18 decimals, so it's already scaled for JLP\\n farmInfo.totalSupplyScaled = lpToken.totalSupply();\\n farmInfo.chefBalanceScaled = pool.totalLpSupply;\\n farmInfo.userLp = user.amount;\\n (farmInfo.userPendingJoe, , , ) = bmcj.pendingTokens(farmInfo.id, userAddress);\\n if (pool.veJoeShareBp == BP_PRECISION) {\\n farmInfo.boostFactor = ~uint256(0);\\n } else {\\n // can't over or underflow, so normal math is fine\\n farmInfo.boostFactor =\\n (pool.veJoeShareBp * BP_PRECISION) /\\n (BP_PRECISION - pool.veJoeShareBp) +\\n BP_PRECISION;\\n }\\n }\\n\\n if (pool.totalLpSupply != 0 && farmInfo.totalSupplyScaled != 0 && farmInfo.chefTotalAlloc != 0 && farmInfo.reserveUsd != 0) {\\n uint256 poolUsdPerYear = UsdPerSec.mul(pool.allocPoint).mul(SEC_PER_YEAR) / farmInfo.chefTotalAlloc;\\n\\n uint256 poolReserveUsd = farmInfo.reserveUsd.mul(farmInfo.chefBalanceScaled) / farmInfo.totalSupplyScaled;\\n\\n if (poolReserveUsd == 0) return;\\n\\n farmInfo.baseAPR =\\n poolUsdPerYear.mul(BP_PRECISION - pool.veJoeShareBp).mul(PRECISION) /\\n poolReserveUsd /\\n BP_PRECISION;\\n\\n if (pool.totalFactor != 0 && user.amount != 0) {\\n uint256 userLpUsd = user.amount.mul(farmInfo.reserveUsd) / pool.totalLpSupply;\\n\\n farmInfo.boostedAPR =\\n poolUsdPerYear.mul(pool.veJoeShareBp).mul(user.factor).div(pool.totalFactor).mul(PRECISION) /\\n userLpUsd /\\n BP_PRECISION;\\n } else {\\n farmInfo.boostedAPR = \\n poolUsdPerYear.mul(pool.veJoeShareBp).mul(PRECISION) /\\n poolReserveUsd /\\n BP_PRECISION;\\n }\\n }\\n }\\n}\\n\",\"keccak256\":\"0x0c4e878889c4d541ade9b15067311f8ad879964ba07a9fc076e4a36c6c27d16d\",\"license\":\"MIT\"},\"contracts/traderjoe/interfaces/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IERC20Joe {\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n function name() external view returns (string memory);\\n\\n function symbol() external view returns (string memory);\\n\\n function decimals() external view returns (uint8);\\n\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address owner) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n function transferFrom(\\n address from,\\n address to,\\n uint256 value\\n ) external returns (bool);\\n}\\n\",\"keccak256\":\"0xd5d59683ac059dc8c7a528d9243a0434d727bcddd4e477d4b26d50ae4f78ea05\",\"license\":\"GPL-3.0\"},\"contracts/traderjoe/interfaces/IJoeERC20.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IJoeERC20 {\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n function name() external pure returns (string memory);\\n\\n function symbol() external pure returns (string memory);\\n\\n function decimals() external pure returns (uint8);\\n\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address owner) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n function transferFrom(\\n address from,\\n address to,\\n uint256 value\\n ) external returns (bool);\\n\\n function DOMAIN_SEPARATOR() external view returns (bytes32);\\n\\n function PERMIT_TYPEHASH() external pure returns (bytes32);\\n\\n function nonces(address owner) external view returns (uint256);\\n\\n function permit(\\n address owner,\\n address spender,\\n uint256 value,\\n uint256 deadline,\\n uint8 v,\\n bytes32 r,\\n bytes32 s\\n ) external;\\n}\\n\",\"keccak256\":\"0x0f9b1de8137e61afcf2c09fde27dc657da98b7c19c1811fd205ffbe877490d36\",\"license\":\"GPL-3.0\"},\"contracts/traderjoe/interfaces/IJoeFactory.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IJoeFactory {\\n event PairCreated(address indexed token0, address indexed token1, address pair, uint256);\\n\\n function feeTo() external view returns (address);\\n\\n function feeToSetter() external view returns (address);\\n\\n function migrator() external view returns (address);\\n\\n function getPair(address tokenA, address tokenB) external view returns (address pair);\\n\\n function allPairs(uint256) external view returns (address pair);\\n\\n function allPairsLength() external view returns (uint256);\\n\\n function createPair(address tokenA, address tokenB) external returns (address pair);\\n\\n function setFeeTo(address) external;\\n\\n function setFeeToSetter(address) external;\\n\\n function setMigrator(address) external;\\n}\\n\",\"keccak256\":\"0x0e31007ead341ae106c1ca874629b527886427f7f47641d96e0d172720f2c3ca\",\"license\":\"GPL-3.0\"},\"contracts/traderjoe/interfaces/IJoePair.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IJoePair {\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n function name() external pure returns (string memory);\\n\\n function symbol() external pure returns (string memory);\\n\\n function decimals() external pure returns (uint8);\\n\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address owner) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n function transferFrom(\\n address from,\\n address to,\\n uint256 value\\n ) external returns (bool);\\n\\n function DOMAIN_SEPARATOR() external view returns (bytes32);\\n\\n function PERMIT_TYPEHASH() external pure returns (bytes32);\\n\\n function nonces(address owner) external view returns (uint256);\\n\\n function permit(\\n address owner,\\n address spender,\\n uint256 value,\\n uint256 deadline,\\n uint8 v,\\n bytes32 r,\\n bytes32 s\\n ) external;\\n\\n event Mint(address indexed sender, uint256 amount0, uint256 amount1);\\n event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);\\n event Swap(\\n address indexed sender,\\n uint256 amount0In,\\n uint256 amount1In,\\n uint256 amount0Out,\\n uint256 amount1Out,\\n address indexed to\\n );\\n event Sync(uint112 reserve0, uint112 reserve1);\\n\\n function MINIMUM_LIQUIDITY() external pure returns (uint256);\\n\\n function factory() external view returns (address);\\n\\n function token0() external view returns (address);\\n\\n function token1() external view returns (address);\\n\\n function getReserves()\\n external\\n view\\n returns (\\n uint112 reserve0,\\n uint112 reserve1,\\n uint32 blockTimestampLast\\n );\\n\\n function price0CumulativeLast() external view returns (uint256);\\n\\n function price1CumulativeLast() external view returns (uint256);\\n\\n function kLast() external view returns (uint256);\\n\\n function mint(address to) external returns (uint256 liquidity);\\n\\n function burn(address to) external returns (uint256 amount0, uint256 amount1);\\n\\n function swap(\\n uint256 amount0Out,\\n uint256 amount1Out,\\n address to,\\n bytes calldata data\\n ) external;\\n\\n function skim(address to) external;\\n\\n function sync() external;\\n\\n function initialize(address, address) external;\\n}\\n\",\"keccak256\":\"0xd4d926f79ca1de45dc3f8a7e8244d62a54522cb1a3f38d881979319363ee1387\",\"license\":\"GPL-3.0\"}},\"version\":1}", - "bytecode": "0x6102006040523480156200001257600080fd5b506040516200339438038062003394833981016040819052620000359162000285565b6001600160601b031960608a811b821660805289811b821660a05288811b821660c05287811b821660e05286811b82166101005285811b82166101205284811b82166101405283811b82166101605282901b16610180526040805163d21220a760e01b815290516001600160a01b038a811692908a169163d21220a791600480820192602092909190829003018186803b158015620000d357600080fd5b505afa158015620000e8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200010e91906200025f565b6001600160a01b03161415156101a081151560f81b81525050876001600160a01b0316866001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156200016b57600080fd5b505afa15801562000180573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620001a691906200025f565b6001600160a01b03161415156101c081151560f81b81525050876001600160a01b0316856001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156200020357600080fd5b505afa15801562000218573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200023e91906200025f565b6001600160a01b03161460f81b6101e0525062000374975050505050505050565b60006020828403121562000271578081fd5b81516200027e816200035b565b9392505050565b60008060008060008060008060006101208a8c031215620002a4578485fd5b8951620002b1816200035b565b60208b0151909950620002c4816200035b565b60408b0151909850620002d7816200035b565b60608b0151909750620002ea816200035b565b60808b0151909650620002fd816200035b565b60a08b015190955062000310816200035b565b60c08b015190945062000323816200035b565b60e08b015190935062000336816200035b565b6101008b01519092506200034a816200035b565b809150509295985092959850929598565b6001600160a01b03811681146200037157600080fd5b50565b60805160601c60a05160601c60c05160601c60e05160601c6101005160601c6101205160601c6101405160601c6101605160601c6101805160601c6101a05160f81c6101c05160f81c6101e05160f81c612efe62000496600039806109b8525080610a05525080610a4f5250806101f5528061053e52806105d852806108635280610ebf5280610eee5280610f8452806119c652508061023d528061040a52806104a452806106a352806107c15250806102e95280610370528061067152806106f452806107865250806107605280610aeb52508061073c528061099752508061091a52806109e45250806107185280610a2e5250806102195280610a8a5280610b1a5280611db652508061028f528061083d52806108d25250612efe6000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c80638a38466e11610097578063cff5dd3311610066578063cff5dd33146101b0578063d02641a0146101b8578063eee5c276146101d8578063f97a496c146101eb576100f5565b80638a38466e146101605780639bbf1deb14610168578063b985a3a014610188578063ce7a198914610190576100f5565b806335541641116100d357806335541641146101285780634e57afe014610148578063685f02e71461015057806387dabe4614610158576100f5565b80630d1dcd9a146100fa578063117be4c2146101185780632c9e2b0514610120575b600080fd5b6101026101f3565b60405161010f9190612b91565b60405180910390f35b610102610217565b61010261023b565b61013b610136366004612517565b61025f565b60405161010f9190612d67565b6101026106f2565b610102610716565b61010261073a565b61010261075e565b61017b610176366004612624565b610782565b60405161010f9190612c1f565b61010261083b565b6101a361019e3660046125c1565b61085f565b60405161010f9190612bbf565b610102610918565b6101cb6101c63660046124df565b61093c565b60405161010f9190612e24565b6101cb6101e63660046124df565b61096b565b6101cb61097c565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b610267612183565b61026f612183565b600061027961098b565b90506000670de0b6b3a76400006102b9836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b90610c41565b816102c057fe5b838552046020808501829052604080516317caf6f160e01b815290519293506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926317caf6f192600480840193919291829003018186803b15801561032d57600080fd5b505afa158015610341573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103659190612831565b8360400181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156103c757600080fd5b505afa1580156103db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ff9190612831565b8360a00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561046157600080fd5b505afa158015610475573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104999190612831565b8360600181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156104fb57600080fd5b505afa15801561050f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105339190612831565b8360c00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561059557600080fd5b505afa1580156105a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105cd9190612831565b8360800181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b15801561062f57600080fd5b505afa158015610643573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106679190612831565b60e08401526106987f0000000000000000000000000000000000000000000000000000000000000000838d8d610c78565b6101008401526106ca7f0000000000000000000000000000000000000000000000000000000000000000838b8b610c78565b6101208401526106dd8282878a8a610ea8565b61014084015250909998505050505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b031614806107f557507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b0316145b61081a5760405162461bcd60e51b815260040161081190612cc6565b60405180910390fd5b600061082461098b565b905061083285828686610c78565b95945050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b0316146108b25760405162461bcd60e51b815260040161081190612c62565b60006108bc61098b565b90506000670de0b6b3a76400006108f6836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b816108fd57fe5b04905061090d8282888888610ea8565b979650505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000670de0b6b3a764000061095b61095261098b565b6102b385610a86565b8161096257fe5b0490505b919050565b600061097682610a86565b92915050565b600061098661098b565b905090565b60006003610a796109dc7f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611297565b610a73610a297f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611297565b610a737f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611297565b9061143c565b81610a8057fe5b04905090565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415610ad15750670de0b6b3a7640000610966565b60405163e6a4390560e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e6a4390590610b429086907f000000000000000000000000000000000000000000000000000000000000000090600401612ba5565b60206040518083038186803b158015610b5a57600080fd5b505afa158015610b6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b9291906124fb565b90506001600160a01b038116610bac576000915050610966565b610c3a81826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015610be957600080fd5b505afa158015610bfd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2191906124fb565b6001600160a01b0316856001600160a01b031614611297565b9392505050565b6000811580610c5c57505080820282828281610c5957fe5b04145b6109765760405162461bcd60e51b815260040161081190612d37565b606081818167ffffffffffffffff81118015610c9357600080fd5b50604051908082528060200260200182016040528015610ccd57816020015b610cba6121dd565b815260200190600190039081610cb25790505b5090506000876001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610d0b57600080fd5b505afa158015610d1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d439190612831565b90506000886001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610d8057600080fd5b505afa158015610d94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610db89190612831565b905060005b84811015610e9a576000888883818110610dd357fe5b905060200201359050610de4612269565b604051631526fe2760e01b81526001600160a01b038d1690631526fe2790610e10908590600401612e24565b60806040518083038186803b158015610e2857600080fd5b505afa158015610e3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6091906126aa565b9050610e798c8c84846000015185602001518a8a61145f565b868481518110610e8557fe5b60209081029190910101525050600101610dbd565b509198975050505050505050565b6060610eb261229a565b60405180606001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610f4557600080fd5b505afa158015610f59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f7d9190612831565b81526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610fdb57600080fd5b505afa158015610fef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110139190612831565b905290508260608167ffffffffffffffff8111801561103157600080fd5b5060405190808252806020026020018201604052801561106b57816020015b6110586122c4565b8152602001906001900390816110505790505b50905060005b8281101561128a57600087878381811061108757fe5b905060200201359050611098612373565b8551604051631526fe2760e01b81526001600160a01b0390911690631526fe27906110c7908590600401612e24565b6101206040518083038186803b1580156110e057600080fd5b505afa1580156110f4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061111891906126fc565b90506111226123bf565b86516040516393f1a40b60e01b81526001600160a01b03909116906393f1a40b906111539086908f90600401612e2d565b60606040518083038186803b15801561116b57600080fd5b505afa15801561117f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a391906127a0565b9050828585815181106111b257fe5b602090810291909101015152865185518690869081106111ce57fe5b602002602001015161012001906001600160a01b031690816001600160a01b031681525050866020015185858151811061120457fe5b6020026020010151610160018181525050866040015185858151811061122657fe5b602002602001015161018001818152505061127f8d670de0b6b3a764000061125b8f8b60400151610c4190919063ffffffff16565b8161126257fe5b048d88888151811061127057fe5b602002602001015186866117a9565b505050600101611071565b5098975050505050505050565b6000806000846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b1580156112d557600080fd5b505afa1580156112e9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061130d91906127dd565b506001600160701b031691506001600160701b0316915060006113a8866001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561136257600080fd5b505afa158015611376573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061139a91906124fb565b6001600160a01b0316611c7f565b60ff16905060006113eb876001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561136257600080fd5b60ff16905085156114295761141e83611418866114138661140d87601261143c565b90611d40565b611d63565b90611d7f565b945050505050610976565b61141e84611418856114138561140d8860125b818101818110156109765760405162461bcd60e51b815260040161081190612c32565b6114676121dd565b6000856001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156114a257600080fd5b505afa1580156114b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114da91906128a9565b60ff169050600061155e876001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561151d57600080fd5b505afa158015611531573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115559190612831565b83601203611d63565b905060006115ea886001600160a01b03166370a082318d6040518263ffffffff1660e01b81526004016115919190612b91565b60206040518083038186803b1580156115a957600080fd5b505afa1580156115bd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115e19190612831565b84601203611d63565b90506000670de0b6b3a76400006116048c6102b38c611db1565b8161160b57fe5b0490506000896001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561164957600080fd5b505afa15801561165d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061168191906124fb565b905060008a6001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156116be57600080fd5b505afa1580156116d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116f691906124fb565b9050604051806101a001604052808d81526020018b81526020018c6001600160a01b03168152602001836001600160a01b03168152602001826001600160a01b0316815260200161174f846001600160a01b03166120b0565b8152602001611766836001600160a01b03166120b0565b81526020018481526020018681526020018f6001600160a01b031681526020018581526020018a8152602001898152509650505050505050979650505050505050565b6000826000015190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b1580156117ed57600080fd5b505afa158015611801573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061182591906124fb565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561186257600080fd5b505afa158015611876573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189a91906124fb565b6020808701516001600160601b0316908801526001600160a01b0380851660408901528381166060890181905290821660808901529091506118db906120b0565b60a08701526118f26001600160a01b0382166120b0565b60c0870152670de0b6b3a764000061190d8a6102b386611db1565b8161191457fe5b048660e0018181525050826001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561195757600080fd5b505afa15801561196b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061198f9190612831565b6101008088019190915285015161014087015283516101a0870152855160405160016232bd9d60e01b031981526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163ffcd4263916119fc91908b90600401612e2d565b60006040518083038186803b158015611a1457600080fd5b505afa158015611a28573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611a509190810190612849565b5050506101c087015260c085015163ffffffff166127101415611a7b57600019610220870152611aa0565b60c08501516127109063ffffffff1680820390820281611a9757fe5b04016102208701525b50505061010082015115801590611abb575061010083015115155b8015611acb575061016083015115155b8015611ada575060e083015115155b15611c77576000836101600151611b0f6301e133806102b386602001516001600160601b03168a610c4190919063ffffffff16565b81611b1657fe5b0490506000846101000151611b3d8661014001518760e00151610c4190919063ffffffff16565b81611b4457fe5b04905080611b53575050611c77565b61271081611b84670de0b6b3a76400006102b38860c0015163ffffffff166127100387610c4190919063ffffffff16565b81611b8b57fe5b0481611b9357fe5b046101e086015260e084015115801590611bad5750825115155b15611c305761010084015160e0860151845160009291611bcd9190610c41565b81611bd457fe5b04905061271081611c14670de0b6b3a76400006102b38960e001516114188a604001516102b38d60c0015163ffffffff168c610c4190919063ffffffff16565b81611c1b57fe5b0481611c2357fe5b0461020087015250611c74565b61271081611c5d670de0b6b3a76400006102b38860c0015163ffffffff1687610c4190919063ffffffff16565b81611c6457fe5b0481611c6c57fe5b046102008601525b50505b505050505050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b179052905160009182916060916001600160a01b03861691611cc69190612b75565b600060405180830381855afa9150503d8060008114611d01576040519150601f19603f3d011682016040523d82523d6000602084013e611d06565b606091505b5091509150818015611d19575080516020145b611d24576012611d38565b80806020019051810190611d3891906128a9565b949350505050565b808203828111156109765760405162461bcd60e51b815260040161081190612c99565b600081611d71575081610976565b610c3a83600a84900a610c41565b6000808211611da05760405162461bcd60e51b815260040161081190612d08565b818381611da957fe5b049392505050565b6000807f00000000000000000000000000000000000000000000000000000000000000009050600080846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015611e1357600080fd5b505afa158015611e27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e4b91906127dd565b506001600160701b031691506001600160701b031691506000856001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015611e9d57600080fd5b505afa158015611eb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ed591906124fb565b90506000866001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015611f1257600080fd5b505afa158015611f26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f4a91906124fb565b90506000611f60836001600160a01b0316611c7f565b60ff1690506000611f79836001600160a01b0316611c7f565b60ff169050611f8d86611413601285611d40565b9550611f9e85611413601284611d40565b9450600080886001600160a01b0316866001600160a01b03161415611fda57670de0b6b3a76400009150611fd38b6001611297565b9050612079565b886001600160a01b0316856001600160a01b0316141561201157611fff8b6000611297565b9150670de0b6b3a76400009050612079565b61201a86610a86565b915061202585610a86565b90508161205c57670de0b6b3a764000061204460026102b38a85610c41565b8161204b57fe5b049950505050505050505050610966565b8061207957670de0b6b3a764000061204460026102b38b86610c41565b670de0b6b3a764000061209961208f8984610c41565b610a738b86610c41565b816120a057fe5b049b9a5050505050505050505050565b60408051600481526024810182526020810180516001600160e01b03166395d89b4160e01b179052905160609160009183916001600160a01b038616916120f79190612b75565b600060405180830381855afa9150503d8060008114612132576040519150601f19603f3d011682016040523d82523d6000602084013e612137565b606091505b509150915081801561214a575060008151115b61216f57604051806040016040528060038152602001623f3f3f60e81b815250611d38565b80806020019051810190611d389190612677565b60405180610160016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016060815260200160608152602001606081525090565b604051806101a00160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806080016040528060006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b604051806102400160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915290565b60405180606001604052806000815260200160008152602001600081525090565b805161097681612e9b565b60008083601f8401126123fc578182fd5b50813567ffffffffffffffff811115612413578182fd5b602083019150836020808302850101111561242d57600080fd5b9250929050565b600082601f830112612444578081fd5b815167ffffffffffffffff81111561245a578182fd5b61246d601f8201601f1916602001612e44565b915080825283602082850101111561248457600080fd5b612495816020840160208601612e6b565b5092915050565b805163ffffffff8116811461097657600080fd5b805167ffffffffffffffff8116811461097657600080fd5b80516001600160601b038116811461097657600080fd5b6000602082840312156124f0578081fd5b8135610c3a81612e9b565b60006020828403121561250c578081fd5b8151610c3a81612e9b565b60008060008060008060006080888a031215612531578283fd5b873567ffffffffffffffff80821115612548578485fd5b6125548b838c016123eb565b909950975060208a013591508082111561256c578485fd5b6125788b838c016123eb565b909750955060408a0135915080821115612590578485fd5b5061259d8a828b016123eb565b90945092505060608801356125b181612e9b565b8091505092959891949750929550565b600080600080606085870312156125d6578384fd5b84356125e181612e9b565b935060208501356125f181612e9b565b9250604085013567ffffffffffffffff81111561260c578283fd5b612618878288016123eb565b95989497509550505050565b600080600060408486031215612638578283fd5b833561264381612e9b565b9250602084013567ffffffffffffffff81111561265e578283fd5b61266a868287016123eb565b9497909650939450505050565b600060208284031215612688578081fd5b815167ffffffffffffffff81111561269e578182fd5b611d3884828501612434565b6000608082840312156126bb578081fd5b6126c56080612e44565b82516126d081612e9b565b808252506020830151602082015260408301516040820152606083015160608201528091505092915050565b600061012080838503121561270f578182fd5b61271881612e44565b905061272484846123e0565b815261273384602085016124c8565b6020820152604083015160408201526060830151606082015261275984608085016124b0565b608082015261276b8460a085016123e0565b60a082015261277d8460c0850161249c565b60c082015260e08381015190820152610100928301519281019290925250919050565b6000606082840312156127b1578081fd5b6127bb6060612e44565b8251815260208301516020820152604083015160408201528091505092915050565b6000806000606084860312156127f1578081fd5b83516127fc81612eb3565b602085015190935061280d81612eb3565b604085015190925063ffffffff81168114612826578182fd5b809150509250925092565b600060208284031215612842578081fd5b5051919050565b6000806000806080858703121561285e578182fd5b84519350602085015161287081612e9b565b604086015190935067ffffffffffffffff81111561288c578283fd5b61289887828801612434565b606096909601519497939650505050565b6000602082840312156128ba578081fd5b815160ff81168114610c3a578182fd5b6000610240825184526020830151602085015260408301516128ef60408601826129d5565b50606083015161290260608601826129d5565b50608083015161291560808601826129d5565b5060a08301518160a086015261292d82860182612b49565b91505060c083015184820360c08601526129478282612b49565b91505060e083015160e085015261010080840151818601525061012080840151612973828701826129d5565b50506101408381015190850152610160808401519085015261018080840151908501526101a080840151908501526101c080840151908501526101e0808401519085015261020080840151908501526102209283015192909301919091525090565b6001600160a01b03169052565b6000815180845260208085018081965082840281019150828601855b85811015612a28578284038952612a168483516128ca565b988501989350908401906001016129fe565b5091979650505050505050565b6000815180845260208085019450848183028601828601855b85811015612b3c57838303895281516101a0815185528682015187860152604080830151612a7e828801826129d5565b5050606080830151612a92828801826129d5565b5050608080830151612aa6828801826129d5565b505060a0808301518282880152612abf83880182612b49565b9250505060c08083015186830382880152612ada8382612b49565b9250505060e080830151818701525061010080830151818701525061012080830151612b08828801826129d5565b5050610140828101519086015261016080830151908601526101809182015191909401529784019790840190600101612a4e565b5090979650505050505050565b60008151808452612b61816020860160208601612e6b565b601f01601f19169290920160200192915050565b60008251612b87818460208701612e6b565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6000602080830181845280855180835260408601915060408482028701019250838701855b82811015612c1257603f19888603018452612c008583516128ca565b94509285019290850190600101612be4565b5092979650505050505050565b600060208252610c3a6020830184612a35565b602080825260169082015275536166654d6174683a20416464204f766572666c6f7760501b604082015260600190565b60208082526019908201527f4661726d4c656e7356323a204f6e6c7920666f7220424d434a00000000000000604082015260600190565b602080825260139082015272536166654d6174683a20556e646572666c6f7760681b604082015260600190565b60208082526022908201527f4661726d4c656e7356323a206f6e6c7920666f72204d43563220616e64204d43604082015261563360f01b606082015260800190565b602080825260159082015274536166654d6174683a20446976206279205a65726f60581b604082015260600190565b602080825260169082015275536166654d6174683a204d756c204f766572666c6f7760501b604082015260600190565b60006020825282516020830152602083015160408301526040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015160e083015260e08301516101008181850152808501519150506101606101208181860152612ddd610180860184612a35565b9250808601519050601f19610140818786030181880152612dfe8584612a35565b908801518782039092018488015293509050612e1a83826129e2565b9695505050505050565b90815260200190565b9182526001600160a01b0316602082015260400190565b60405181810167ffffffffffffffff81118282101715612e6357600080fd5b604052919050565b60005b83811015612e86578181015183820152602001612e6e565b83811115612e95576000848401525b50505050565b6001600160a01b0381168114612eb057600080fd5b50565b6001600160701b0381168114612eb057600080fdfea2646970667358221220e79148a5b8b4605cc16f9b893c0762257ac307c0da3da832151514c00184b62264736f6c634300060c0033", - "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100f55760003560e01c80638a38466e11610097578063cff5dd3311610066578063cff5dd33146101b0578063d02641a0146101b8578063eee5c276146101d8578063f97a496c146101eb576100f5565b80638a38466e146101605780639bbf1deb14610168578063b985a3a014610188578063ce7a198914610190576100f5565b806335541641116100d357806335541641146101285780634e57afe014610148578063685f02e71461015057806387dabe4614610158576100f5565b80630d1dcd9a146100fa578063117be4c2146101185780632c9e2b0514610120575b600080fd5b6101026101f3565b60405161010f9190612b91565b60405180910390f35b610102610217565b61010261023b565b61013b610136366004612517565b61025f565b60405161010f9190612d67565b6101026106f2565b610102610716565b61010261073a565b61010261075e565b61017b610176366004612624565b610782565b60405161010f9190612c1f565b61010261083b565b6101a361019e3660046125c1565b61085f565b60405161010f9190612bbf565b610102610918565b6101cb6101c63660046124df565b61093c565b60405161010f9190612e24565b6101cb6101e63660046124df565b61096b565b6101cb61097c565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b610267612183565b61026f612183565b600061027961098b565b90506000670de0b6b3a76400006102b9836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b90610c41565b816102c057fe5b838552046020808501829052604080516317caf6f160e01b815290519293506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926317caf6f192600480840193919291829003018186803b15801561032d57600080fd5b505afa158015610341573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103659190612831565b8360400181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156103c757600080fd5b505afa1580156103db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ff9190612831565b8360a00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561046157600080fd5b505afa158015610475573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104999190612831565b8360600181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156104fb57600080fd5b505afa15801561050f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105339190612831565b8360c00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561059557600080fd5b505afa1580156105a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105cd9190612831565b8360800181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b15801561062f57600080fd5b505afa158015610643573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106679190612831565b60e08401526106987f0000000000000000000000000000000000000000000000000000000000000000838d8d610c78565b6101008401526106ca7f0000000000000000000000000000000000000000000000000000000000000000838b8b610c78565b6101208401526106dd8282878a8a610ea8565b61014084015250909998505050505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b031614806107f557507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b0316145b61081a5760405162461bcd60e51b815260040161081190612cc6565b60405180910390fd5b600061082461098b565b905061083285828686610c78565b95945050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b0316146108b25760405162461bcd60e51b815260040161081190612c62565b60006108bc61098b565b90506000670de0b6b3a76400006108f6836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b816108fd57fe5b04905061090d8282888888610ea8565b979650505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000670de0b6b3a764000061095b61095261098b565b6102b385610a86565b8161096257fe5b0490505b919050565b600061097682610a86565b92915050565b600061098661098b565b905090565b60006003610a796109dc7f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611297565b610a73610a297f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611297565b610a737f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611297565b9061143c565b81610a8057fe5b04905090565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415610ad15750670de0b6b3a7640000610966565b60405163e6a4390560e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e6a4390590610b429086907f000000000000000000000000000000000000000000000000000000000000000090600401612ba5565b60206040518083038186803b158015610b5a57600080fd5b505afa158015610b6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b9291906124fb565b90506001600160a01b038116610bac576000915050610966565b610c3a81826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015610be957600080fd5b505afa158015610bfd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2191906124fb565b6001600160a01b0316856001600160a01b031614611297565b9392505050565b6000811580610c5c57505080820282828281610c5957fe5b04145b6109765760405162461bcd60e51b815260040161081190612d37565b606081818167ffffffffffffffff81118015610c9357600080fd5b50604051908082528060200260200182016040528015610ccd57816020015b610cba6121dd565b815260200190600190039081610cb25790505b5090506000876001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610d0b57600080fd5b505afa158015610d1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d439190612831565b90506000886001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610d8057600080fd5b505afa158015610d94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610db89190612831565b905060005b84811015610e9a576000888883818110610dd357fe5b905060200201359050610de4612269565b604051631526fe2760e01b81526001600160a01b038d1690631526fe2790610e10908590600401612e24565b60806040518083038186803b158015610e2857600080fd5b505afa158015610e3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6091906126aa565b9050610e798c8c84846000015185602001518a8a61145f565b868481518110610e8557fe5b60209081029190910101525050600101610dbd565b509198975050505050505050565b6060610eb261229a565b60405180606001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610f4557600080fd5b505afa158015610f59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f7d9190612831565b81526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610fdb57600080fd5b505afa158015610fef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110139190612831565b905290508260608167ffffffffffffffff8111801561103157600080fd5b5060405190808252806020026020018201604052801561106b57816020015b6110586122c4565b8152602001906001900390816110505790505b50905060005b8281101561128a57600087878381811061108757fe5b905060200201359050611098612373565b8551604051631526fe2760e01b81526001600160a01b0390911690631526fe27906110c7908590600401612e24565b6101206040518083038186803b1580156110e057600080fd5b505afa1580156110f4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061111891906126fc565b90506111226123bf565b86516040516393f1a40b60e01b81526001600160a01b03909116906393f1a40b906111539086908f90600401612e2d565b60606040518083038186803b15801561116b57600080fd5b505afa15801561117f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a391906127a0565b9050828585815181106111b257fe5b602090810291909101015152865185518690869081106111ce57fe5b602002602001015161012001906001600160a01b031690816001600160a01b031681525050866020015185858151811061120457fe5b6020026020010151610160018181525050866040015185858151811061122657fe5b602002602001015161018001818152505061127f8d670de0b6b3a764000061125b8f8b60400151610c4190919063ffffffff16565b8161126257fe5b048d88888151811061127057fe5b602002602001015186866117a9565b505050600101611071565b5098975050505050505050565b6000806000846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b1580156112d557600080fd5b505afa1580156112e9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061130d91906127dd565b506001600160701b031691506001600160701b0316915060006113a8866001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561136257600080fd5b505afa158015611376573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061139a91906124fb565b6001600160a01b0316611c7f565b60ff16905060006113eb876001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561136257600080fd5b60ff16905085156114295761141e83611418866114138661140d87601261143c565b90611d40565b611d63565b90611d7f565b945050505050610976565b61141e84611418856114138561140d8860125b818101818110156109765760405162461bcd60e51b815260040161081190612c32565b6114676121dd565b6000856001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156114a257600080fd5b505afa1580156114b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114da91906128a9565b60ff169050600061155e876001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561151d57600080fd5b505afa158015611531573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115559190612831565b83601203611d63565b905060006115ea886001600160a01b03166370a082318d6040518263ffffffff1660e01b81526004016115919190612b91565b60206040518083038186803b1580156115a957600080fd5b505afa1580156115bd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115e19190612831565b84601203611d63565b90506000670de0b6b3a76400006116048c6102b38c611db1565b8161160b57fe5b0490506000896001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561164957600080fd5b505afa15801561165d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061168191906124fb565b905060008a6001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156116be57600080fd5b505afa1580156116d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116f691906124fb565b9050604051806101a001604052808d81526020018b81526020018c6001600160a01b03168152602001836001600160a01b03168152602001826001600160a01b0316815260200161174f846001600160a01b03166120b0565b8152602001611766836001600160a01b03166120b0565b81526020018481526020018681526020018f6001600160a01b031681526020018581526020018a8152602001898152509650505050505050979650505050505050565b6000826000015190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b1580156117ed57600080fd5b505afa158015611801573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061182591906124fb565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561186257600080fd5b505afa158015611876573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189a91906124fb565b6020808701516001600160601b0316908801526001600160a01b0380851660408901528381166060890181905290821660808901529091506118db906120b0565b60a08701526118f26001600160a01b0382166120b0565b60c0870152670de0b6b3a764000061190d8a6102b386611db1565b8161191457fe5b048660e0018181525050826001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561195757600080fd5b505afa15801561196b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061198f9190612831565b6101008088019190915285015161014087015283516101a0870152855160405160016232bd9d60e01b031981526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163ffcd4263916119fc91908b90600401612e2d565b60006040518083038186803b158015611a1457600080fd5b505afa158015611a28573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611a509190810190612849565b5050506101c087015260c085015163ffffffff166127101415611a7b57600019610220870152611aa0565b60c08501516127109063ffffffff1680820390820281611a9757fe5b04016102208701525b50505061010082015115801590611abb575061010083015115155b8015611acb575061016083015115155b8015611ada575060e083015115155b15611c77576000836101600151611b0f6301e133806102b386602001516001600160601b03168a610c4190919063ffffffff16565b81611b1657fe5b0490506000846101000151611b3d8661014001518760e00151610c4190919063ffffffff16565b81611b4457fe5b04905080611b53575050611c77565b61271081611b84670de0b6b3a76400006102b38860c0015163ffffffff166127100387610c4190919063ffffffff16565b81611b8b57fe5b0481611b9357fe5b046101e086015260e084015115801590611bad5750825115155b15611c305761010084015160e0860151845160009291611bcd9190610c41565b81611bd457fe5b04905061271081611c14670de0b6b3a76400006102b38960e001516114188a604001516102b38d60c0015163ffffffff168c610c4190919063ffffffff16565b81611c1b57fe5b0481611c2357fe5b0461020087015250611c74565b61271081611c5d670de0b6b3a76400006102b38860c0015163ffffffff1687610c4190919063ffffffff16565b81611c6457fe5b0481611c6c57fe5b046102008601525b50505b505050505050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b179052905160009182916060916001600160a01b03861691611cc69190612b75565b600060405180830381855afa9150503d8060008114611d01576040519150601f19603f3d011682016040523d82523d6000602084013e611d06565b606091505b5091509150818015611d19575080516020145b611d24576012611d38565b80806020019051810190611d3891906128a9565b949350505050565b808203828111156109765760405162461bcd60e51b815260040161081190612c99565b600081611d71575081610976565b610c3a83600a84900a610c41565b6000808211611da05760405162461bcd60e51b815260040161081190612d08565b818381611da957fe5b049392505050565b6000807f00000000000000000000000000000000000000000000000000000000000000009050600080846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015611e1357600080fd5b505afa158015611e27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e4b91906127dd565b506001600160701b031691506001600160701b031691506000856001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015611e9d57600080fd5b505afa158015611eb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ed591906124fb565b90506000866001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015611f1257600080fd5b505afa158015611f26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f4a91906124fb565b90506000611f60836001600160a01b0316611c7f565b60ff1690506000611f79836001600160a01b0316611c7f565b60ff169050611f8d86611413601285611d40565b9550611f9e85611413601284611d40565b9450600080886001600160a01b0316866001600160a01b03161415611fda57670de0b6b3a76400009150611fd38b6001611297565b9050612079565b886001600160a01b0316856001600160a01b0316141561201157611fff8b6000611297565b9150670de0b6b3a76400009050612079565b61201a86610a86565b915061202585610a86565b90508161205c57670de0b6b3a764000061204460026102b38a85610c41565b8161204b57fe5b049950505050505050505050610966565b8061207957670de0b6b3a764000061204460026102b38b86610c41565b670de0b6b3a764000061209961208f8984610c41565b610a738b86610c41565b816120a057fe5b049b9a5050505050505050505050565b60408051600481526024810182526020810180516001600160e01b03166395d89b4160e01b179052905160609160009183916001600160a01b038616916120f79190612b75565b600060405180830381855afa9150503d8060008114612132576040519150601f19603f3d011682016040523d82523d6000602084013e612137565b606091505b509150915081801561214a575060008151115b61216f57604051806040016040528060038152602001623f3f3f60e81b815250611d38565b80806020019051810190611d389190612677565b60405180610160016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016060815260200160608152602001606081525090565b604051806101a00160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806080016040528060006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b604051806102400160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915290565b60405180606001604052806000815260200160008152602001600081525090565b805161097681612e9b565b60008083601f8401126123fc578182fd5b50813567ffffffffffffffff811115612413578182fd5b602083019150836020808302850101111561242d57600080fd5b9250929050565b600082601f830112612444578081fd5b815167ffffffffffffffff81111561245a578182fd5b61246d601f8201601f1916602001612e44565b915080825283602082850101111561248457600080fd5b612495816020840160208601612e6b565b5092915050565b805163ffffffff8116811461097657600080fd5b805167ffffffffffffffff8116811461097657600080fd5b80516001600160601b038116811461097657600080fd5b6000602082840312156124f0578081fd5b8135610c3a81612e9b565b60006020828403121561250c578081fd5b8151610c3a81612e9b565b60008060008060008060006080888a031215612531578283fd5b873567ffffffffffffffff80821115612548578485fd5b6125548b838c016123eb565b909950975060208a013591508082111561256c578485fd5b6125788b838c016123eb565b909750955060408a0135915080821115612590578485fd5b5061259d8a828b016123eb565b90945092505060608801356125b181612e9b565b8091505092959891949750929550565b600080600080606085870312156125d6578384fd5b84356125e181612e9b565b935060208501356125f181612e9b565b9250604085013567ffffffffffffffff81111561260c578283fd5b612618878288016123eb565b95989497509550505050565b600080600060408486031215612638578283fd5b833561264381612e9b565b9250602084013567ffffffffffffffff81111561265e578283fd5b61266a868287016123eb565b9497909650939450505050565b600060208284031215612688578081fd5b815167ffffffffffffffff81111561269e578182fd5b611d3884828501612434565b6000608082840312156126bb578081fd5b6126c56080612e44565b82516126d081612e9b565b808252506020830151602082015260408301516040820152606083015160608201528091505092915050565b600061012080838503121561270f578182fd5b61271881612e44565b905061272484846123e0565b815261273384602085016124c8565b6020820152604083015160408201526060830151606082015261275984608085016124b0565b608082015261276b8460a085016123e0565b60a082015261277d8460c0850161249c565b60c082015260e08381015190820152610100928301519281019290925250919050565b6000606082840312156127b1578081fd5b6127bb6060612e44565b8251815260208301516020820152604083015160408201528091505092915050565b6000806000606084860312156127f1578081fd5b83516127fc81612eb3565b602085015190935061280d81612eb3565b604085015190925063ffffffff81168114612826578182fd5b809150509250925092565b600060208284031215612842578081fd5b5051919050565b6000806000806080858703121561285e578182fd5b84519350602085015161287081612e9b565b604086015190935067ffffffffffffffff81111561288c578283fd5b61289887828801612434565b606096909601519497939650505050565b6000602082840312156128ba578081fd5b815160ff81168114610c3a578182fd5b6000610240825184526020830151602085015260408301516128ef60408601826129d5565b50606083015161290260608601826129d5565b50608083015161291560808601826129d5565b5060a08301518160a086015261292d82860182612b49565b91505060c083015184820360c08601526129478282612b49565b91505060e083015160e085015261010080840151818601525061012080840151612973828701826129d5565b50506101408381015190850152610160808401519085015261018080840151908501526101a080840151908501526101c080840151908501526101e0808401519085015261020080840151908501526102209283015192909301919091525090565b6001600160a01b03169052565b6000815180845260208085018081965082840281019150828601855b85811015612a28578284038952612a168483516128ca565b988501989350908401906001016129fe565b5091979650505050505050565b6000815180845260208085019450848183028601828601855b85811015612b3c57838303895281516101a0815185528682015187860152604080830151612a7e828801826129d5565b5050606080830151612a92828801826129d5565b5050608080830151612aa6828801826129d5565b505060a0808301518282880152612abf83880182612b49565b9250505060c08083015186830382880152612ada8382612b49565b9250505060e080830151818701525061010080830151818701525061012080830151612b08828801826129d5565b5050610140828101519086015261016080830151908601526101809182015191909401529784019790840190600101612a4e565b5090979650505050505050565b60008151808452612b61816020860160208601612e6b565b601f01601f19169290920160200192915050565b60008251612b87818460208701612e6b565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6000602080830181845280855180835260408601915060408482028701019250838701855b82811015612c1257603f19888603018452612c008583516128ca565b94509285019290850190600101612be4565b5092979650505050505050565b600060208252610c3a6020830184612a35565b602080825260169082015275536166654d6174683a20416464204f766572666c6f7760501b604082015260600190565b60208082526019908201527f4661726d4c656e7356323a204f6e6c7920666f7220424d434a00000000000000604082015260600190565b602080825260139082015272536166654d6174683a20556e646572666c6f7760681b604082015260600190565b60208082526022908201527f4661726d4c656e7356323a206f6e6c7920666f72204d43563220616e64204d43604082015261563360f01b606082015260800190565b602080825260159082015274536166654d6174683a20446976206279205a65726f60581b604082015260600190565b602080825260169082015275536166654d6174683a204d756c204f766572666c6f7760501b604082015260600190565b60006020825282516020830152602083015160408301526040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015160e083015260e08301516101008181850152808501519150506101606101208181860152612ddd610180860184612a35565b9250808601519050601f19610140818786030181880152612dfe8584612a35565b908801518782039092018488015293509050612e1a83826129e2565b9695505050505050565b90815260200190565b9182526001600160a01b0316602082015260400190565b60405181810167ffffffffffffffff81118282101715612e6357600080fd5b604052919050565b60005b83811015612e86578181015183820152602001612e6e565b83811115612e95576000848401525b50505050565b6001600160a01b0381168114612eb057600080fd5b50565b6001600160701b0381168114612eb057600080fdfea2646970667358221220e79148a5b8b4605cc16f9b893c0762257ac307c0da3da832151514c00184b62264736f6c634300060c0033", + "numDeployments": 2, + "solcInputHash": "05be5b065453cde7967331fef060caff", + "metadata": "{\"compiler\":{\"version\":\"0.6.12+commit.27d51765\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_joe\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"_wavax\",\"type\":\"address\"},{\"internalType\":\"contract IJoePair\",\"name\":\"_wavaxUsdte\",\"type\":\"address\"},{\"internalType\":\"contract IJoePair\",\"name\":\"_wavaxUsdce\",\"type\":\"address\"},{\"internalType\":\"contract IJoePair\",\"name\":\"_wavaxUsdc\",\"type\":\"address\"},{\"internalType\":\"contract IJoeFactory\",\"name\":\"_joeFactory\",\"type\":\"address\"},{\"internalType\":\"contract IMasterChef\",\"name\":\"_chefv2\",\"type\":\"address\"},{\"internalType\":\"contract IMasterChef\",\"name\":\"_chefv3\",\"type\":\"address\"},{\"internalType\":\"contract IBoostedMasterchef\",\"name\":\"_bmcj\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"bmcj\",\"outputs\":[{\"internalType\":\"contract IBoostedMasterchef\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"chefv2\",\"outputs\":[{\"internalType\":\"contract IMasterChef\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"chefv3\",\"outputs\":[{\"internalType\":\"contract IMasterChef\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPidsV2\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPidsV3\",\"type\":\"uint256[]\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPidsBMCJ\",\"type\":\"uint256[]\"},{\"internalType\":\"address\",\"name\":\"user\",\"type\":\"address\"}],\"name\":\"getAllFarmData\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"avaxPriceUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePriceUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAllocChefV2\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAllocChefV3\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAllocBMCJ\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePerSecChefV2\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePerSecChefV3\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePerSecBMCJ\",\"type\":\"uint256\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfo[]\",\"name\":\"farmInfosV2\",\"type\":\"tuple[]\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfo[]\",\"name\":\"farmInfosV3\",\"type\":\"tuple[]\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"baseApr\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"averageBoostedApr\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"veJoeShareBp\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePriceUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userLp\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userPendingJoe\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userBoostedApr\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userFactorShare\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfoBMCJ[]\",\"name\":\"farmInfosBMCJ\",\"type\":\"tuple[]\"}],\"internalType\":\"struct FarmLensV2.AllFarmData\",\"name\":\"\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getAvaxPrice\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"contract IBoostedMasterchef\",\"name\":\"chef\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"user\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPids\",\"type\":\"uint256[]\"}],\"name\":\"getBMCJFarmInfos\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"baseApr\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"averageBoostedApr\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"veJoeShareBp\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"joePriceUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userLp\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userPendingJoe\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userBoostedApr\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"userFactorShare\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfoBMCJ[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"}],\"name\":\"getDerivedAvaxPriceOfToken\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"contract IMasterChef\",\"name\":\"chef\",\"type\":\"address\"},{\"internalType\":\"uint256[]\",\"name\":\"whitelistedPids\",\"type\":\"uint256[]\"}],\"name\":\"getMCFarmInfos\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"allocPoint\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"lpAddress\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token0Address\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token1Address\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"token0Symbol\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"token1Symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"reserveUsd\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalSupplyScaled\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"chefAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chefBalanceScaled\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefTotalAlloc\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"chefJoePerSec\",\"type\":\"uint256\"}],\"internalType\":\"struct FarmLensV2.FarmInfo[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"}],\"name\":\"getTokenPrice\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"joe\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"joeFactory\",\"outputs\":[{\"internalType\":\"contract IJoeFactory\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavax\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavaxUsdc\",\"outputs\":[{\"internalType\":\"contract IJoePair\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavaxUsdce\",\"outputs\":[{\"internalType\":\"contract IJoePair\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"wavaxUsdte\",\"outputs\":[{\"internalType\":\"contract IJoePair\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"getAllFarmData(uint256[],uint256[],uint256[],address)\":{\"params\":{\"user\":\"The address of the user, if address(0), returns global info\",\"whitelistedPidsBMCJ\":\"Array of all ids of pools that are whitelisted in BMCJ\",\"whitelistedPidsV2\":\"Array of all ids of pools that are whitelisted in chefV2\",\"whitelistedPidsV3\":\"Array of all ids of pools that are whitelisted in chefV3\"},\"returns\":{\"_0\":\"AllFarmData The information of all the whitelisted farms of MCV2, MCV3 and BMCJ\"}},\"getAvaxPrice()\":{\"returns\":{\"_0\":\"uint256 the avax price, scaled to 18 decimals\"}},\"getBMCJFarmInfos(address,address,uint256[])\":{\"params\":{\"chef\":\"The address of the MasterChef\",\"user\":\"The address of the user, if address(0), returns global info\",\"whitelistedPids\":\"Array of all ids of pools that are whitelisted and valid to have their farm data returned\"},\"returns\":{\"_0\":\"FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\"}},\"getDerivedAvaxPriceOfToken(address)\":{\"params\":{\"token\":\"The address of the token\"},\"returns\":{\"_0\":\"uint256 the token derived price, scaled to 18 decimals\"}},\"getMCFarmInfos(address,uint256[])\":{\"params\":{\"chef\":\"The address of the MasterChef\",\"whitelistedPids\":\"Array of all ids of pools that are whitelisted and valid to have their farm data returned\"},\"returns\":{\"_0\":\"FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\"}},\"getTokenPrice(address)\":{\"params\":{\"token\":\"The address of the token\"},\"returns\":{\"_0\":\"uint256 the Usd price of token, scaled to 18 decimals\"}}},\"stateVariables\":{\"SEC_PER_YEAR\":{\"details\":\"365 * 86400, hard coding it for gas optimisation\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"getAllFarmData(uint256[],uint256[],uint256[],address)\":{\"notice\":\"Get all data needed for useFarms hook.\"},\"getAvaxPrice()\":{\"notice\":\"Returns the price of avax in Usd\"},\"getBMCJFarmInfos(address,address,uint256[])\":{\"notice\":\"Returns the farm pairs data for BoostedMasterChefJoe\"},\"getDerivedAvaxPriceOfToken(address)\":{\"notice\":\"Returns the derived price of token, it needs to be paired with wavax\"},\"getMCFarmInfos(address,uint256[])\":{\"notice\":\"Returns the farm pairs data for MCV2 and MCV3\"},\"getTokenPrice(address)\":{\"notice\":\"Returns the Usd price of token, it needs to be paired with wavax\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"contracts/traderjoe/FarmLensV2.sol\":\"FarmLensV2\"},\"evmVersion\":\"istanbul\",\"libraries\":{\"__CACHE_BREAKER__\":\"0x00000000d41867734bbee4c6863d9255b2b06ac1\"},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"contracts/interfaces/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\n\\ninterface IERC20 {\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address account) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 amount) external returns (bool);\\n\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n\\n // EIP 2612\\n function permit(\\n address owner,\\n address spender,\\n uint256 value,\\n uint256 deadline,\\n uint8 v,\\n bytes32 r,\\n bytes32 s\\n ) external;\\n}\\n\",\"keccak256\":\"0xa3fb82796e80f566a5c47f9a1f2ade7de7f390dfdc06bea5375112b9f9314f40\",\"license\":\"MIT\"},\"contracts/libraries/SafeERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\n\\nimport \\\"../interfaces/IERC20.sol\\\";\\n\\nlibrary SafeERC20 {\\n function safeSymbol(IERC20 token) internal view returns (string memory) {\\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x95d89b41));\\n return success && data.length > 0 ? abi.decode(data, (string)) : \\\"???\\\";\\n }\\n\\n function safeName(IERC20 token) internal view returns (string memory) {\\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x06fdde03));\\n return success && data.length > 0 ? abi.decode(data, (string)) : \\\"???\\\";\\n }\\n\\n function safeDecimals(IERC20 token) internal view returns (uint8) {\\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x313ce567));\\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\\n }\\n\\n function safeTransfer(\\n IERC20 token,\\n address to,\\n uint256 amount\\n ) internal {\\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(0xa9059cbb, to, amount));\\n require(success && (data.length == 0 || abi.decode(data, (bool))), \\\"SafeERC20: Transfer failed\\\");\\n }\\n\\n function safeTransferFrom(\\n IERC20 token,\\n address from,\\n uint256 amount\\n ) internal {\\n (bool success, bytes memory data) = address(token).call(\\n abi.encodeWithSelector(0x23b872dd, from, address(this), amount)\\n );\\n require(success && (data.length == 0 || abi.decode(data, (bool))), \\\"SafeERC20: TransferFrom failed\\\");\\n }\\n}\\n\",\"keccak256\":\"0xdd77ee6d503b5396208d64e811ee89ca55389c62071003cc223f4ea0029c10ac\",\"license\":\"MIT\"},\"contracts/libraries/SafeMath.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\n\\n// a library for performing overflow-safe math, updated with awesomeness from of DappHub (https://github.com/dapphub/ds-math)\\nlibrary SafeMath {\\n function add(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require((c = a + b) >= b, \\\"SafeMath: Add Overflow\\\");\\n }\\n\\n function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require((c = a - b) <= a, \\\"SafeMath: Underflow\\\");\\n }\\n\\n function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require(b == 0 || (c = a * b) / b == a, \\\"SafeMath: Mul Overflow\\\");\\n }\\n\\n function div(uint256 a, uint256 b) internal pure returns (uint256 c) {\\n require(b > 0, \\\"SafeMath: Div by Zero\\\");\\n c = a / b;\\n }\\n\\n function to128(uint256 a) internal pure returns (uint128 c) {\\n require(a <= uint128(-1), \\\"SafeMath: uint128 Overflow\\\");\\n c = uint128(a);\\n }\\n}\\n\\nlibrary SafeMath128 {\\n function add(uint128 a, uint128 b) internal pure returns (uint128 c) {\\n require((c = a + b) >= b, \\\"SafeMath: Add Overflow\\\");\\n }\\n\\n function sub(uint128 a, uint128 b) internal pure returns (uint128 c) {\\n require((c = a - b) <= a, \\\"SafeMath: Underflow\\\");\\n }\\n}\\n\",\"keccak256\":\"0x8b8dcb649a07667a9a97c050a374a82389e7a19254abaebedf399c00619042a8\",\"license\":\"MIT\"},\"contracts/traderjoe/FarmLensV2.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.6.12;\\npragma experimental ABIEncoderV2;\\nimport \\\"../libraries/SafeMath.sol\\\";\\nimport \\\"../libraries/SafeERC20.sol\\\";\\n\\nimport \\\"./interfaces/IERC20.sol\\\";\\nimport \\\"./interfaces/IJoeERC20.sol\\\";\\nimport \\\"./interfaces/IJoePair.sol\\\";\\nimport \\\"./interfaces/IJoeFactory.sol\\\";\\n\\ninterface IMasterChef {\\n struct PoolInfo {\\n IJoeERC20 lpToken; // Address of LP token contract.\\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\\n }\\n\\n function poolLength() external view returns (uint256);\\n\\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\\n\\n function totalAllocPoint() external view returns (uint256);\\n\\n function joePerSec() external view returns (uint256);\\n}\\n\\ninterface IBoostedMasterchef {\\n struct UserInfo {\\n uint256 amount;\\n uint256 rewardDebt;\\n uint256 factor;\\n }\\n\\n struct PoolInfo {\\n IERC20 lpToken;\\n uint96 allocPoint;\\n uint256 accJoePerShare;\\n uint256 accJoePerFactorPerShare;\\n uint64 lastRewardTimestamp;\\n address rewarder;\\n uint32 veJoeShareBp;\\n uint256 totalFactor;\\n uint256 totalLpSupply;\\n }\\n\\n function userInfo(uint256 _pid, address user) external view returns (UserInfo memory);\\n\\n function pendingTokens(uint256 _pid, address user)\\n external\\n view\\n returns (\\n uint256,\\n address,\\n string memory,\\n uint256\\n );\\n\\n function poolLength() external view returns (uint256);\\n\\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\\n\\n function totalAllocPoint() external view returns (uint256);\\n\\n function joePerSec() external view returns (uint256);\\n}\\n\\ncontract FarmLensV2 {\\n using SafeMath for uint256;\\n using SafeERC20 for IERC20;\\n\\n struct FarmInfo {\\n uint256 id;\\n uint256 allocPoint;\\n address lpAddress;\\n address token0Address;\\n address token1Address;\\n string token0Symbol;\\n string token1Symbol;\\n uint256 reserveUsd;\\n uint256 totalSupplyScaled;\\n address chefAddress;\\n uint256 chefBalanceScaled;\\n uint256 chefTotalAlloc;\\n uint256 chefJoePerSec;\\n }\\n\\n struct FarmInfoBMCJ {\\n uint256 id;\\n uint256 allocPoint;\\n address lpAddress;\\n address token0Address;\\n address token1Address;\\n string token0Symbol;\\n string token1Symbol;\\n uint256 reserveUsd;\\n uint256 totalSupplyScaled;\\n address chefAddress;\\n uint256 chefBalanceScaled;\\n uint256 chefTotalAlloc;\\n uint256 chefJoePerSec;\\n uint256 baseApr;\\n uint256 averageBoostedApr;\\n uint256 veJoeShareBp;\\n uint256 joePriceUsd;\\n\\n uint256 userLp;\\n uint256 userPendingJoe;\\n uint256 userBoostedApr;\\n uint256 userFactorShare;\\n }\\n\\n struct AllFarmData {\\n uint256 avaxPriceUsd;\\n uint256 joePriceUsd;\\n uint256 totalAllocChefV2;\\n uint256 totalAllocChefV3;\\n uint256 totalAllocBMCJ;\\n uint256 joePerSecChefV2;\\n uint256 joePerSecChefV3;\\n uint256 joePerSecBMCJ;\\n FarmInfo[] farmInfosV2;\\n FarmInfo[] farmInfosV3;\\n FarmInfoBMCJ[] farmInfosBMCJ;\\n }\\n\\n struct GlobalInfo {\\n address chef;\\n uint256 totalAlloc;\\n uint256 joePerSec;\\n }\\n\\n /// @dev 365 * 86400, hard coding it for gas optimisation\\n uint256 private constant SEC_PER_YEAR = 31536000;\\n uint256 private constant BP_PRECISION = 10_000;\\n uint256 private constant PRECISION = 1e18;\\n\\n address public immutable joe; // 0x6e84a6216eA6dACC71eE8E6b0a5B7322EEbC0fDd;\\n address public immutable wavax; // 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7;\\n IJoePair public immutable wavaxUsdte; // 0xeD8CBD9F0cE3C6986b22002F03c6475CEb7a6256\\n IJoePair public immutable wavaxUsdce; // 0xA389f9430876455C36478DeEa9769B7Ca4E3DDB1\\n IJoePair public immutable wavaxUsdc; // 0xf4003f4efbe8691b60249e6afbd307abe7758adb\\n IJoeFactory public immutable joeFactory; // 0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10\\n IMasterChef public immutable chefv2; // 0xd6a4F121CA35509aF06A0Be99093d08462f53052\\n IMasterChef public immutable chefv3; // 0x188bED1968b795d5c9022F6a0bb5931Ac4c18F00\\n IBoostedMasterchef public immutable bmcj; // Not deployed yet\\n bool private immutable isWavaxToken1InWavaxUsdte;\\n bool private immutable isWavaxToken1InWavaxUsdce;\\n bool private immutable isWavaxToken1InWavaxUsdc;\\n\\n constructor(\\n address _joe,\\n address _wavax,\\n IJoePair _wavaxUsdte,\\n IJoePair _wavaxUsdce,\\n IJoePair _wavaxUsdc,\\n IJoeFactory _joeFactory,\\n IMasterChef _chefv2,\\n IMasterChef _chefv3,\\n IBoostedMasterchef _bmcj\\n ) public {\\n joe = _joe;\\n wavax = _wavax;\\n wavaxUsdte = _wavaxUsdte;\\n wavaxUsdce = _wavaxUsdce;\\n wavaxUsdc = _wavaxUsdc;\\n joeFactory = _joeFactory;\\n chefv2 = _chefv2;\\n chefv3 = _chefv3;\\n bmcj = _bmcj;\\n\\n isWavaxToken1InWavaxUsdte = _wavaxUsdte.token1() == _wavax;\\n isWavaxToken1InWavaxUsdce = _wavaxUsdce.token1() == _wavax;\\n isWavaxToken1InWavaxUsdc = _wavaxUsdc.token1() == _wavax;\\n }\\n\\n /// @notice Returns the price of avax in Usd\\n /// @return uint256 the avax price, scaled to 18 decimals\\n function getAvaxPrice() external view returns (uint256) {\\n return _getAvaxPrice();\\n }\\n\\n /// @notice Returns the derived price of token, it needs to be paired with wavax\\n /// @param token The address of the token\\n /// @return uint256 the token derived price, scaled to 18 decimals\\n function getDerivedAvaxPriceOfToken(address token) external view returns (uint256) {\\n return _getDerivedAvaxPriceOfToken(token);\\n }\\n\\n /// @notice Returns the Usd price of token, it needs to be paired with wavax\\n /// @param token The address of the token\\n /// @return uint256 the Usd price of token, scaled to 18 decimals\\n function getTokenPrice(address token) external view returns (uint256) {\\n return _getDerivedAvaxPriceOfToken(token).mul(_getAvaxPrice()) / 1e18;\\n }\\n\\n /// @notice Returns the farm pairs data for MCV2 and MCV3\\n /// @param chef The address of the MasterChef\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\\n function getMCFarmInfos(IMasterChef chef, uint256[] calldata whitelistedPids)\\n external\\n view\\n returns (FarmInfo[] memory)\\n {\\n require(chef == chefv2 || chef == chefv3, \\\"FarmLensV2: only for MCV2 and MCV3\\\");\\n\\n uint256 avaxPrice = _getAvaxPrice();\\n return _getMCFarmInfos(chef, avaxPrice, whitelistedPids);\\n }\\n\\n /// @notice Returns the farm pairs data for BoostedMasterChefJoe\\n /// @param chef The address of the MasterChef\\n /// @param user The address of the user, if address(0), returns global info\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\\n function getBMCJFarmInfos(\\n IBoostedMasterchef chef,\\n address user,\\n uint256[] calldata whitelistedPids\\n ) external view returns (FarmInfoBMCJ[] memory) {\\n require(chef == bmcj, \\\"FarmLensV2: Only for BMCJ\\\");\\n\\n uint256 avaxPrice = _getAvaxPrice();\\n uint256 joePrice = _getDerivedAvaxPriceOfToken(joe).mul(avaxPrice) / PRECISION;\\n return _getBMCJFarmInfos(avaxPrice, joePrice, user, whitelistedPids);\\n }\\n\\n /// @notice Get all data needed for useFarms hook.\\n /// @param whitelistedPidsV2 Array of all ids of pools that are whitelisted in chefV2\\n /// @param whitelistedPidsV3 Array of all ids of pools that are whitelisted in chefV3\\n /// @param whitelistedPidsBMCJ Array of all ids of pools that are whitelisted in BMCJ\\n /// @param user The address of the user, if address(0), returns global info\\n /// @return AllFarmData The information of all the whitelisted farms of MCV2, MCV3 and BMCJ\\n function getAllFarmData(\\n uint256[] calldata whitelistedPidsV2,\\n uint256[] calldata whitelistedPidsV3,\\n uint256[] calldata whitelistedPidsBMCJ,\\n address user\\n ) external view returns (AllFarmData memory) {\\n AllFarmData memory allFarmData;\\n\\n uint256 avaxPrice = _getAvaxPrice();\\n uint256 joePrice = _getDerivedAvaxPriceOfToken(joe).mul(avaxPrice) / PRECISION;\\n\\n allFarmData.avaxPriceUsd = avaxPrice;\\n allFarmData.joePriceUsd = joePrice;\\n\\n allFarmData.totalAllocChefV2 = chefv2.totalAllocPoint();\\n allFarmData.joePerSecChefV2 = chefv2.joePerSec();\\n\\n allFarmData.totalAllocChefV3 = chefv3.totalAllocPoint();\\n allFarmData.joePerSecChefV3 = chefv3.joePerSec();\\n\\n allFarmData.totalAllocBMCJ = bmcj.totalAllocPoint();\\n allFarmData.joePerSecBMCJ = bmcj.joePerSec();\\n\\n allFarmData.farmInfosV2 = _getMCFarmInfos(chefv2, avaxPrice, whitelistedPidsV2);\\n allFarmData.farmInfosV3 = _getMCFarmInfos(chefv3, avaxPrice, whitelistedPidsV3);\\n allFarmData.farmInfosBMCJ = _getBMCJFarmInfos(avaxPrice, joePrice, user, whitelistedPidsBMCJ);\\n\\n return allFarmData;\\n }\\n\\n /// @notice Returns the price of avax in Usd internally\\n /// @return uint256 the avax price, scaled to 18 decimals\\n function _getAvaxPrice() private view returns (uint256) {\\n return\\n _getDerivedTokenPriceOfPair(wavaxUsdte, isWavaxToken1InWavaxUsdte)\\n .add(_getDerivedTokenPriceOfPair(wavaxUsdce, isWavaxToken1InWavaxUsdce))\\n .add(_getDerivedTokenPriceOfPair(wavaxUsdc, isWavaxToken1InWavaxUsdc)) / 3;\\n }\\n\\n /// @notice Returns the derived price of token in the other token\\n /// @param pair The address of the pair\\n /// @param derivedtoken0 If price should be derived from token0 if true, or token1 if false\\n /// @return uint256 the derived price, scaled to 18 decimals\\n function _getDerivedTokenPriceOfPair(IJoePair pair, bool derivedtoken0) private view returns (uint256) {\\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\\n uint256 decimals0 = IERC20(pair.token0()).safeDecimals();\\n uint256 decimals1 = IERC20(pair.token1()).safeDecimals();\\n\\n if (derivedtoken0) {\\n return _scaleTo(reserve0, decimals1.add(18).sub(decimals0)).div(reserve1);\\n } else {\\n return _scaleTo(reserve1, decimals0.add(18).sub(decimals1)).div(reserve0);\\n }\\n }\\n\\n /// @notice Returns the derived price of token, it needs to be paired with wavax\\n /// @param token The address of the token\\n /// @return uint256 the token derived price, scaled to 18 decimals\\n function _getDerivedAvaxPriceOfToken(address token) private view returns (uint256) {\\n if (token == wavax) {\\n return PRECISION;\\n }\\n IJoePair pair = IJoePair(joeFactory.getPair(token, wavax));\\n if (address(pair) == address(0)) {\\n return 0;\\n }\\n // instead of testing wavax == pair.token0(), we do the opposite to save gas\\n return _getDerivedTokenPriceOfPair(pair, token == pair.token1());\\n }\\n\\n /// @notice Returns the amount scaled to decimals\\n /// @param amount The amount\\n /// @param decimals The decimals to scale `amount`\\n /// @return uint256 The amount scaled to decimals\\n function _scaleTo(uint256 amount, uint256 decimals) private pure returns (uint256) {\\n if (decimals == 0) return amount;\\n return amount.mul(10**decimals);\\n }\\n\\n /// @notice Returns the derived avax liquidity, at least one of the token needs to be paired with wavax\\n /// @param pair The address of the pair\\n /// @return uint256 the derived price of pair's liquidity, scaled to 18 decimals\\n function _getDerivedAvaxLiquidityOfPair(IJoePair pair) private view returns (uint256) {\\n address _wavax = wavax;\\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\\n IERC20 token0 = IERC20(pair.token0());\\n IERC20 token1 = IERC20(pair.token1());\\n uint256 decimals0 = token0.safeDecimals();\\n uint256 decimals1 = token1.safeDecimals();\\n\\n reserve0 = _scaleTo(reserve0, uint256(18).sub(decimals0));\\n reserve1 = _scaleTo(reserve1, uint256(18).sub(decimals1));\\n\\n uint256 token0DerivedAvaxPrice;\\n uint256 token1DerivedAvaxPrice;\\n if (address(token0) == _wavax) {\\n token0DerivedAvaxPrice = PRECISION;\\n token1DerivedAvaxPrice = _getDerivedTokenPriceOfPair(pair, true);\\n } else if (address(token1) == _wavax) {\\n token0DerivedAvaxPrice = _getDerivedTokenPriceOfPair(pair, false);\\n token1DerivedAvaxPrice = PRECISION;\\n } else {\\n token0DerivedAvaxPrice = _getDerivedAvaxPriceOfToken(address(token0));\\n token1DerivedAvaxPrice = _getDerivedAvaxPriceOfToken(address(token1));\\n // If one token isn't paired with wavax, then we hope that the second one is.\\n // E.g, TOKEN/UsdC, token might not be paired with wavax, but UsdC is.\\n // If both aren't paired with wavax, return 0\\n if (token0DerivedAvaxPrice == 0) return reserve1.mul(token1DerivedAvaxPrice).mul(2) / PRECISION;\\n if (token1DerivedAvaxPrice == 0) return reserve0.mul(token0DerivedAvaxPrice).mul(2) / PRECISION;\\n }\\n return reserve0.mul(token0DerivedAvaxPrice).add(reserve1.mul(token1DerivedAvaxPrice)) / PRECISION;\\n }\\n\\n /// @notice Private function to return the farm pairs data for a given MasterChef (V2 or V3)\\n /// @param chef The address of the MasterChef\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\\n function _getMCFarmInfos(\\n IMasterChef chef,\\n uint256 avaxPrice,\\n uint256[] calldata whitelistedPids\\n ) private view returns (FarmInfo[] memory) {\\n uint256 whitelistLength = whitelistedPids.length;\\n FarmInfo[] memory farmInfos = new FarmInfo[](whitelistLength);\\n\\n uint256 chefTotalAlloc = chef.totalAllocPoint();\\n uint256 chefJoePerSec = chef.joePerSec();\\n\\n for (uint256 i; i < whitelistLength; i++) {\\n uint256 pid = whitelistedPids[i];\\n IMasterChef.PoolInfo memory pool = chef.poolInfo(pid);\\n\\n farmInfos[i] = _getMCFarmInfo(\\n chef,\\n avaxPrice,\\n pid,\\n IJoePair(address(pool.lpToken)),\\n pool.allocPoint,\\n chefTotalAlloc,\\n chefJoePerSec\\n );\\n }\\n\\n return farmInfos;\\n }\\n\\n /// @notice Helper function to return the farm info of a given pool\\n /// @param chef The address of the MasterChef\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param pid The pid of the pool\\n /// @param lpToken The lpToken of the pool\\n /// @param allocPoint The allocPoint of the pool\\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\\n function _getMCFarmInfo(\\n IMasterChef chef,\\n uint256 avaxPrice,\\n uint256 pid,\\n IJoePair lpToken,\\n uint256 allocPoint,\\n uint256 totalAllocPoint,\\n uint256 chefJoePerSec\\n ) private view returns (FarmInfo memory) {\\n uint256 decimals = lpToken.decimals();\\n uint256 totalSupplyScaled = _scaleTo(lpToken.totalSupply(), 18 - decimals);\\n uint256 chefBalanceScaled = _scaleTo(lpToken.balanceOf(address(chef)), 18 - decimals);\\n uint256 reserveUsd = _getDerivedAvaxLiquidityOfPair(lpToken).mul(avaxPrice) / PRECISION;\\n IERC20 token0 = IERC20(lpToken.token0());\\n IERC20 token1 = IERC20(lpToken.token1());\\n\\n return\\n FarmInfo({\\n id: pid,\\n allocPoint: allocPoint,\\n lpAddress: address(lpToken),\\n token0Address: address(token0),\\n token1Address: address(token1),\\n token0Symbol: token0.safeSymbol(),\\n token1Symbol: token1.safeSymbol(),\\n reserveUsd: reserveUsd,\\n totalSupplyScaled: totalSupplyScaled,\\n chefBalanceScaled: chefBalanceScaled,\\n chefAddress: address(chef),\\n chefTotalAlloc: totalAllocPoint,\\n chefJoePerSec: chefJoePerSec\\n });\\n }\\n\\n /// @notice Private function to return the farm pairs data for boostedMasterChef\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param joePrice The joe price as a parameter to save gas\\n /// @param user The address of the user, if address(0), returns global info\\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\\n /// @return FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\\n function _getBMCJFarmInfos(\\n uint256 avaxPrice,\\n uint256 joePrice,\\n address user,\\n uint256[] calldata whitelistedPids\\n ) private view returns (FarmInfoBMCJ[] memory) {\\n GlobalInfo memory globalInfo = GlobalInfo(address(bmcj), bmcj.totalAllocPoint(), bmcj.joePerSec());\\n\\n uint256 whitelistLength = whitelistedPids.length;\\n FarmInfoBMCJ[] memory farmInfos = new FarmInfoBMCJ[](whitelistLength);\\n\\n for (uint256 i; i < whitelistLength; i++) {\\n uint256 pid = whitelistedPids[i];\\n IBoostedMasterchef.PoolInfo memory pool = IBoostedMasterchef(globalInfo.chef).poolInfo(pid);\\n IBoostedMasterchef.UserInfo memory userInfo;\\n userInfo = IBoostedMasterchef(globalInfo.chef).userInfo(pid, user);\\n\\n farmInfos[i].id = pid;\\n farmInfos[i].chefAddress = globalInfo.chef;\\n farmInfos[i].chefTotalAlloc = globalInfo.totalAlloc;\\n farmInfos[i].chefJoePerSec = globalInfo.joePerSec;\\n farmInfos[i].joePriceUsd = joePrice;\\n _getBMCJFarmInfo(\\n avaxPrice,\\n globalInfo.joePerSec.mul(joePrice) / PRECISION,\\n user,\\n farmInfos[i],\\n pool,\\n userInfo\\n );\\n }\\n\\n return farmInfos;\\n }\\n\\n /// @notice Helper function to return the farm info of a given pool of BMCJ\\n /// @param avaxPrice The avax price as a parameter to save gas\\n /// @param UsdPerSec The Usd per sec emitted to BMCJ\\n /// @param userAddress The address of the user\\n /// @param farmInfo The farmInfo of that pool\\n /// @param user The user information\\n function _getBMCJFarmInfo(\\n uint256 avaxPrice,\\n uint256 UsdPerSec,\\n address userAddress,\\n FarmInfoBMCJ memory farmInfo,\\n IBoostedMasterchef.PoolInfo memory pool,\\n IBoostedMasterchef.UserInfo memory user\\n ) private view {\\n {\\n IJoePair lpToken = IJoePair(address(pool.lpToken));\\n IERC20 token0 = IERC20(lpToken.token0());\\n IERC20 token1 = IERC20(lpToken.token1());\\n\\n farmInfo.allocPoint = pool.allocPoint;\\n farmInfo.lpAddress = address(lpToken);\\n farmInfo.token0Address = address(token0);\\n farmInfo.token1Address = address(token1);\\n farmInfo.token0Symbol = token0.safeSymbol();\\n farmInfo.token1Symbol = token1.safeSymbol();\\n farmInfo.reserveUsd = _getDerivedAvaxLiquidityOfPair(lpToken).mul(avaxPrice) / PRECISION;\\n // LP is in 18 decimals, so it's already scaled for JLP\\n farmInfo.totalSupplyScaled = lpToken.totalSupply();\\n farmInfo.chefBalanceScaled = pool.totalLpSupply;\\n farmInfo.userLp = user.amount;\\n farmInfo.veJoeShareBp = pool.veJoeShareBp;\\n (farmInfo.userPendingJoe, , , ) = bmcj.pendingTokens(farmInfo.id, userAddress);\\n }\\n\\n if (\\n pool.totalLpSupply != 0 &&\\n farmInfo.totalSupplyScaled != 0 &&\\n farmInfo.chefTotalAlloc != 0 &&\\n farmInfo.reserveUsd != 0\\n ) {\\n uint256 poolUsdPerYear = UsdPerSec.mul(pool.allocPoint).mul(SEC_PER_YEAR) / farmInfo.chefTotalAlloc;\\n\\n uint256 poolReserveUsd = farmInfo.reserveUsd.mul(farmInfo.chefBalanceScaled) / farmInfo.totalSupplyScaled;\\n\\n if (poolReserveUsd == 0) return;\\n\\n farmInfo.baseApr =\\n poolUsdPerYear.mul(BP_PRECISION - pool.veJoeShareBp).mul(PRECISION) /\\n poolReserveUsd /\\n BP_PRECISION;\\n\\n if (pool.totalFactor != 0) {\\n farmInfo.averageBoostedApr =\\n poolUsdPerYear.mul(pool.veJoeShareBp).mul(PRECISION) /\\n poolReserveUsd /\\n BP_PRECISION;\\n\\n if (user.amount != 0 && user.factor != 0) {\\n uint256 userLpUsd = user.amount.mul(farmInfo.reserveUsd) / pool.totalLpSupply;\\n\\n farmInfo.userBoostedApr =\\n poolUsdPerYear.mul(pool.veJoeShareBp).mul(user.factor).div(pool.totalFactor).mul(PRECISION) /\\n userLpUsd /\\n BP_PRECISION;\\n\\n farmInfo.userFactorShare = user.factor.mul(PRECISION) / pool.totalFactor;\\n }\\n }\\n }\\n }\\n}\\n\",\"keccak256\":\"0x93f525a9c2a0119a9aff852479f9f112f71f9ed66fb17424318768dadb32439a\",\"license\":\"MIT\"},\"contracts/traderjoe/interfaces/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IERC20Joe {\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n function name() external view returns (string memory);\\n\\n function symbol() external view returns (string memory);\\n\\n function decimals() external view returns (uint8);\\n\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address owner) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n function transferFrom(\\n address from,\\n address to,\\n uint256 value\\n ) external returns (bool);\\n}\\n\",\"keccak256\":\"0xd5d59683ac059dc8c7a528d9243a0434d727bcddd4e477d4b26d50ae4f78ea05\",\"license\":\"GPL-3.0\"},\"contracts/traderjoe/interfaces/IJoeERC20.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IJoeERC20 {\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n function name() external pure returns (string memory);\\n\\n function symbol() external pure returns (string memory);\\n\\n function decimals() external pure returns (uint8);\\n\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address owner) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n function transferFrom(\\n address from,\\n address to,\\n uint256 value\\n ) external returns (bool);\\n\\n function DOMAIN_SEPARATOR() external view returns (bytes32);\\n\\n function PERMIT_TYPEHASH() external pure returns (bytes32);\\n\\n function nonces(address owner) external view returns (uint256);\\n\\n function permit(\\n address owner,\\n address spender,\\n uint256 value,\\n uint256 deadline,\\n uint8 v,\\n bytes32 r,\\n bytes32 s\\n ) external;\\n}\\n\",\"keccak256\":\"0x0f9b1de8137e61afcf2c09fde27dc657da98b7c19c1811fd205ffbe877490d36\",\"license\":\"GPL-3.0\"},\"contracts/traderjoe/interfaces/IJoeFactory.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IJoeFactory {\\n event PairCreated(address indexed token0, address indexed token1, address pair, uint256);\\n\\n function feeTo() external view returns (address);\\n\\n function feeToSetter() external view returns (address);\\n\\n function migrator() external view returns (address);\\n\\n function getPair(address tokenA, address tokenB) external view returns (address pair);\\n\\n function allPairs(uint256) external view returns (address pair);\\n\\n function allPairsLength() external view returns (uint256);\\n\\n function createPair(address tokenA, address tokenB) external returns (address pair);\\n\\n function setFeeTo(address) external;\\n\\n function setFeeToSetter(address) external;\\n\\n function setMigrator(address) external;\\n}\\n\",\"keccak256\":\"0x0e31007ead341ae106c1ca874629b527886427f7f47641d96e0d172720f2c3ca\",\"license\":\"GPL-3.0\"},\"contracts/traderjoe/interfaces/IJoePair.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-3.0\\n\\npragma solidity >=0.5.0;\\n\\ninterface IJoePair {\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n function name() external pure returns (string memory);\\n\\n function symbol() external pure returns (string memory);\\n\\n function decimals() external pure returns (uint8);\\n\\n function totalSupply() external view returns (uint256);\\n\\n function balanceOf(address owner) external view returns (uint256);\\n\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n function transferFrom(\\n address from,\\n address to,\\n uint256 value\\n ) external returns (bool);\\n\\n function DOMAIN_SEPARATOR() external view returns (bytes32);\\n\\n function PERMIT_TYPEHASH() external pure returns (bytes32);\\n\\n function nonces(address owner) external view returns (uint256);\\n\\n function permit(\\n address owner,\\n address spender,\\n uint256 value,\\n uint256 deadline,\\n uint8 v,\\n bytes32 r,\\n bytes32 s\\n ) external;\\n\\n event Mint(address indexed sender, uint256 amount0, uint256 amount1);\\n event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);\\n event Swap(\\n address indexed sender,\\n uint256 amount0In,\\n uint256 amount1In,\\n uint256 amount0Out,\\n uint256 amount1Out,\\n address indexed to\\n );\\n event Sync(uint112 reserve0, uint112 reserve1);\\n\\n function MINIMUM_LIQUIDITY() external pure returns (uint256);\\n\\n function factory() external view returns (address);\\n\\n function token0() external view returns (address);\\n\\n function token1() external view returns (address);\\n\\n function getReserves()\\n external\\n view\\n returns (\\n uint112 reserve0,\\n uint112 reserve1,\\n uint32 blockTimestampLast\\n );\\n\\n function price0CumulativeLast() external view returns (uint256);\\n\\n function price1CumulativeLast() external view returns (uint256);\\n\\n function kLast() external view returns (uint256);\\n\\n function mint(address to) external returns (uint256 liquidity);\\n\\n function burn(address to) external returns (uint256 amount0, uint256 amount1);\\n\\n function swap(\\n uint256 amount0Out,\\n uint256 amount1Out,\\n address to,\\n bytes calldata data\\n ) external;\\n\\n function skim(address to) external;\\n\\n function sync() external;\\n\\n function initialize(address, address) external;\\n}\\n\",\"keccak256\":\"0xd4d926f79ca1de45dc3f8a7e8244d62a54522cb1a3f38d881979319363ee1387\",\"license\":\"GPL-3.0\"}},\"version\":1}", + "bytecode": "0x6102006040523480156200001257600080fd5b50604051620034e0380380620034e0833981016040819052620000359162000285565b6001600160601b031960608a811b821660805289811b821660a05288811b821660c05287811b821660e05286811b82166101005285811b82166101205284811b82166101405283811b82166101605282901b16610180526040805163d21220a760e01b815290516001600160a01b038a811692908a169163d21220a791600480820192602092909190829003018186803b158015620000d357600080fd5b505afa158015620000e8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200010e91906200025f565b6001600160a01b03161415156101a081151560f81b81525050876001600160a01b0316866001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156200016b57600080fd5b505afa15801562000180573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620001a691906200025f565b6001600160a01b03161415156101c081151560f81b81525050876001600160a01b0316856001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156200020357600080fd5b505afa15801562000218573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200023e91906200025f565b6001600160a01b03161460f81b6101e0525062000374975050505050505050565b60006020828403121562000271578081fd5b81516200027e816200035b565b9392505050565b60008060008060008060008060006101208a8c031215620002a4578485fd5b8951620002b1816200035b565b60208b0151909950620002c4816200035b565b60408b0151909850620002d7816200035b565b60608b0151909750620002ea816200035b565b60808b0151909650620002fd816200035b565b60a08b015190955062000310816200035b565b60c08b015190945062000323816200035b565b60e08b015190935062000336816200035b565b6101008b01519092506200034a816200035b565b809150509295985092959850929598565b6001600160a01b03811681146200037157600080fd5b50565b60805160601c60a05160601c60c05160601c60e05160601c6101005160601c6101205160601c6101405160601c6101605160601c6101805160601c6101a05160f81c6101c05160f81c6101e05160f81c61304a62000496600039806109b8525080610a05525080610a4f5250806101f5528061053e52806105d852806108635280610ebf5280610eee5280610f8452806119f552508061023d528061040a52806104a452806106a352806107c15250806102e95280610370528061067152806106f452806107865250806107605280610aeb52508061073c528061099752508061091a52806109e45250806107185280610a2e5250806102195280610a8a5280610b1a5280611dcd52508061028f528061083d52806108d2525061304a6000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c80638a38466e11610097578063cff5dd3311610066578063cff5dd33146101b0578063d02641a0146101b8578063eee5c276146101d8578063f97a496c146101eb576100f5565b80638a38466e146101605780639bbf1deb14610168578063b985a3a014610188578063ce7a198914610190576100f5565b806335541641116100d357806335541641146101285780634e57afe014610148578063685f02e71461015057806387dabe4614610158576100f5565b80630d1dcd9a146100fa578063117be4c2146101185780632c9e2b0514610120575b600080fd5b6101026101f3565b60405161010f9190612bc4565b60405180910390f35b610102610217565b61010261023b565b61013b610136366004612543565b61025f565b60405161010f9190612eb3565b6101026106f2565b610102610716565b61010261073a565b61010261075e565b61017b610176366004612650565b610782565b60405161010f9190612d6b565b61010261083b565b6101a361019e3660046125ed565b61085f565b60405161010f9190612bf2565b610102610918565b6101cb6101c636600461250b565b61093c565b60405161010f9190612f70565b6101cb6101e636600461250b565b61096b565b6101cb61097c565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b61026761219a565b61026f61219a565b600061027961098b565b90506000670de0b6b3a76400006102b9836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b90610c41565b816102c057fe5b838552046020808501829052604080516317caf6f160e01b815290519293506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926317caf6f192600480840193919291829003018186803b15801561032d57600080fd5b505afa158015610341573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610365919061285d565b8360400181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156103c757600080fd5b505afa1580156103db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ff919061285d565b8360a00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561046157600080fd5b505afa158015610475573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610499919061285d565b8360600181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156104fb57600080fd5b505afa15801561050f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610533919061285d565b8360c00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561059557600080fd5b505afa1580156105a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105cd919061285d565b8360800181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b15801561062f57600080fd5b505afa158015610643573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610667919061285d565b60e08401526106987f0000000000000000000000000000000000000000000000000000000000000000838d8d610c78565b6101008401526106ca7f0000000000000000000000000000000000000000000000000000000000000000838b8b610c78565b6101208401526106dd8282878a8a610ea8565b61014084015250909998505050505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b031614806107f557507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b0316145b61081a5760405162461bcd60e51b815260040161081190612e12565b60405180910390fd5b600061082461098b565b905061083285828686610c78565b95945050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b0316146108b25760405162461bcd60e51b815260040161081190612dae565b60006108bc61098b565b90506000670de0b6b3a76400006108f6836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b816108fd57fe5b04905061090d8282888888610ea8565b979650505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000670de0b6b3a764000061095b61095261098b565b6102b385610a86565b8161096257fe5b0490505b919050565b600061097682610a86565b92915050565b600061098661098b565b905090565b60006003610a796109dc7f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006112b5565b610a73610a297f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006112b5565b610a737f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006112b5565b9061145a565b81610a8057fe5b04905090565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415610ad15750670de0b6b3a7640000610966565b60405163e6a4390560e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e6a4390590610b429086907f000000000000000000000000000000000000000000000000000000000000000090600401612bd8565b60206040518083038186803b158015610b5a57600080fd5b505afa158015610b6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b929190612527565b90506001600160a01b038116610bac576000915050610966565b610c3a81826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015610be957600080fd5b505afa158015610bfd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c219190612527565b6001600160a01b0316856001600160a01b0316146112b5565b9392505050565b6000811580610c5c57505080820282828281610c5957fe5b04145b6109765760405162461bcd60e51b815260040161081190612e83565b606081818167ffffffffffffffff81118015610c9357600080fd5b50604051908082528060200260200182016040528015610ccd57816020015b610cba6121f4565b815260200190600190039081610cb25790505b5090506000876001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610d0b57600080fd5b505afa158015610d1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d43919061285d565b90506000886001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610d8057600080fd5b505afa158015610d94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610db8919061285d565b905060005b84811015610e9a576000888883818110610dd357fe5b905060200201359050610de4612280565b604051631526fe2760e01b81526001600160a01b038d1690631526fe2790610e10908590600401612f70565b60806040518083038186803b158015610e2857600080fd5b505afa158015610e3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6091906126d6565b9050610e798c8c84846000015185602001518a8a61147d565b868481518110610e8557fe5b60209081029190910101525050600101610dbd565b509198975050505050505050565b6060610eb26122b1565b60405180606001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610f4557600080fd5b505afa158015610f59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f7d919061285d565b81526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610fdb57600080fd5b505afa158015610fef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611013919061285d565b905290508260608167ffffffffffffffff8111801561103157600080fd5b5060405190808252806020026020018201604052801561106b57816020015b6110586122db565b8152602001906001900390816110505790505b50905060005b828110156112a857600087878381811061108757fe5b90506020020135905061109861239f565b8551604051631526fe2760e01b81526001600160a01b0390911690631526fe27906110c7908590600401612f70565b6101206040518083038186803b1580156110e057600080fd5b505afa1580156110f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111189190612728565b90506111226123eb565b86516040516393f1a40b60e01b81526001600160a01b03909116906393f1a40b906111539086908f90600401612f79565b60606040518083038186803b15801561116b57600080fd5b505afa15801561117f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a391906127cc565b9050828585815181106111b257fe5b602090810291909101015152865185518690869081106111ce57fe5b602002602001015161012001906001600160a01b031690816001600160a01b031681525050866020015185858151811061120457fe5b6020026020010151610160018181525050866040015185858151811061122657fe5b60200260200101516101800181815250508b85858151811061124457fe5b602002602001015161020001818152505061129d8d670de0b6b3a76400006112798f8b60400151610c4190919063ffffffff16565b8161128057fe5b048d88888151811061128e57fe5b602002602001015186866117c7565b505050600101611071565b5098975050505050505050565b6000806000846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b1580156112f357600080fd5b505afa158015611307573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061132b9190612809565b506001600160701b031691506001600160701b0316915060006113c6866001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561138057600080fd5b505afa158015611394573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b89190612527565b6001600160a01b0316611c96565b60ff1690506000611409876001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561138057600080fd5b60ff16905085156114475761143c83611436866114318661142b87601261145a565b90611d57565b611d7a565b90611d96565b945050505050610976565b61143c84611436856114318561142b8860125b818101818110156109765760405162461bcd60e51b815260040161081190612d7e565b6114856121f4565b6000856001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156114c057600080fd5b505afa1580156114d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114f891906128d5565b60ff169050600061157c876001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561153b57600080fd5b505afa15801561154f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611573919061285d565b83601203611d7a565b90506000611608886001600160a01b03166370a082318d6040518263ffffffff1660e01b81526004016115af9190612bc4565b60206040518083038186803b1580156115c757600080fd5b505afa1580156115db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ff919061285d565b84601203611d7a565b90506000670de0b6b3a76400006116228c6102b38c611dc8565b8161162957fe5b0490506000896001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561166757600080fd5b505afa15801561167b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061169f9190612527565b905060008a6001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156116dc57600080fd5b505afa1580156116f0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117149190612527565b9050604051806101a001604052808d81526020018b81526020018c6001600160a01b03168152602001836001600160a01b03168152602001826001600160a01b0316815260200161176d846001600160a01b03166120c7565b8152602001611784836001600160a01b03166120c7565b81526020018481526020018681526020018f6001600160a01b031681526020018581526020018a8152602001898152509650505050505050979650505050505050565b6000826000015190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561180b57600080fd5b505afa15801561181f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118439190612527565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561188057600080fd5b505afa158015611894573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118b89190612527565b6020808701516001600160601b0316908801526001600160a01b0380851660408901528381166060890181905290821660808901529091506118f9906120c7565b60a08701526119106001600160a01b0382166120c7565b60c0870152670de0b6b3a764000061192b8a6102b386611dc8565b8161193257fe5b048660e0018181525050826001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561197557600080fd5b505afa158015611989573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119ad919061285d565b61010080880191909152850151610140870152835161022087015260c085015163ffffffff166101e0870152855160405160016232bd9d60e01b031981526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163ffcd426391611a2b91908b90600401612f79565b60006040518083038186803b158015611a4357600080fd5b505afa158015611a57573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611a7f9190810190612875565b50505061024087015250505061010082015115801590611aa3575061010083015115155b8015611ab3575061016083015115155b8015611ac2575060e083015115155b15611c8e576000836101600151611af76301e133806102b386602001516001600160601b03168a610c4190919063ffffffff16565b81611afe57fe5b0490506000846101000151611b258661014001518760e00151610c4190919063ffffffff16565b81611b2c57fe5b04905080611b3b575050611c8e565b61271081611b6c670de0b6b3a76400006102b38860c0015163ffffffff166127100387610c4190919063ffffffff16565b81611b7357fe5b0481611b7b57fe5b046101a086015260e084015115611c8b5761271081611bb9670de0b6b3a76400006102b38860c0015163ffffffff1687610c4190919063ffffffff16565b81611bc057fe5b0481611bc857fe5b046101c0860152825115801590611be25750604083015115155b15611c8b5761010084015160e0860151845160009291611c029190610c41565b81611c0957fe5b04905061271081611c49670de0b6b3a76400006102b38960e001516114368a604001516102b38d60c0015163ffffffff168c610c4190919063ffffffff16565b81611c5057fe5b0481611c5857fe5b0461026087015260e08501516040850151611c7b90670de0b6b3a7640000610c41565b81611c8257fe5b04610280870152505b50505b505050505050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b179052905160009182916060916001600160a01b03861691611cdd9190612ba8565b600060405180830381855afa9150503d8060008114611d18576040519150601f19603f3d011682016040523d82523d6000602084013e611d1d565b606091505b5091509150818015611d30575080516020145b611d3b576012611d4f565b80806020019051810190611d4f91906128d5565b949350505050565b808203828111156109765760405162461bcd60e51b815260040161081190612de5565b600081611d88575081610976565b610c3a83600a84900a610c41565b6000808211611db75760405162461bcd60e51b815260040161081190612e54565b818381611dc057fe5b049392505050565b6000807f00000000000000000000000000000000000000000000000000000000000000009050600080846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015611e2a57600080fd5b505afa158015611e3e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e629190612809565b506001600160701b031691506001600160701b031691506000856001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015611eb457600080fd5b505afa158015611ec8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611eec9190612527565b90506000866001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015611f2957600080fd5b505afa158015611f3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f619190612527565b90506000611f77836001600160a01b0316611c96565b60ff1690506000611f90836001600160a01b0316611c96565b60ff169050611fa486611431601285611d57565b9550611fb585611431601284611d57565b9450600080886001600160a01b0316866001600160a01b03161415611ff157670de0b6b3a76400009150611fea8b60016112b5565b9050612090565b886001600160a01b0316856001600160a01b03161415612028576120168b60006112b5565b9150670de0b6b3a76400009050612090565b61203186610a86565b915061203c85610a86565b90508161207357670de0b6b3a764000061205b60026102b38a85610c41565b8161206257fe5b049950505050505050505050610966565b8061209057670de0b6b3a764000061205b60026102b38b86610c41565b670de0b6b3a76400006120b06120a68984610c41565b610a738b86610c41565b816120b757fe5b049b9a5050505050505050505050565b60408051600481526024810182526020810180516001600160e01b03166395d89b4160e01b179052905160609160009183916001600160a01b0386169161210e9190612ba8565b600060405180830381855afa9150503d8060008114612149576040519150601f19603f3d011682016040523d82523d6000602084013e61214e565b606091505b5091509150818015612161575060008151115b61218657604051806040016040528060038152602001623f3f3f60e81b815250611d4f565b80806020019051810190611d4f91906126a3565b60405180610160016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016060815260200160608152602001606081525090565b604051806101a00160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806080016040528060006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b604051806102a00160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915290565b60405180606001604052806000815260200160008152602001600081525090565b805161097681612fe7565b60008083601f840112612428578182fd5b50813567ffffffffffffffff81111561243f578182fd5b602083019150836020808302850101111561245957600080fd5b9250929050565b600082601f830112612470578081fd5b815167ffffffffffffffff811115612486578182fd5b612499601f8201601f1916602001612f90565b91508082528360208285010111156124b057600080fd5b6124c1816020840160208601612fb7565b5092915050565b805163ffffffff8116811461097657600080fd5b805167ffffffffffffffff8116811461097657600080fd5b80516001600160601b038116811461097657600080fd5b60006020828403121561251c578081fd5b8135610c3a81612fe7565b600060208284031215612538578081fd5b8151610c3a81612fe7565b60008060008060008060006080888a03121561255d578283fd5b873567ffffffffffffffff80821115612574578485fd5b6125808b838c01612417565b909950975060208a0135915080821115612598578485fd5b6125a48b838c01612417565b909750955060408a01359150808211156125bc578485fd5b506125c98a828b01612417565b90945092505060608801356125dd81612fe7565b8091505092959891949750929550565b60008060008060608587031215612602578384fd5b843561260d81612fe7565b9350602085013561261d81612fe7565b9250604085013567ffffffffffffffff811115612638578283fd5b61264487828801612417565b95989497509550505050565b600080600060408486031215612664578283fd5b833561266f81612fe7565b9250602084013567ffffffffffffffff81111561268a578283fd5b61269686828701612417565b9497909650939450505050565b6000602082840312156126b4578081fd5b815167ffffffffffffffff8111156126ca578182fd5b611d4f84828501612460565b6000608082840312156126e7578081fd5b6126f16080612f90565b82516126fc81612fe7565b808252506020830151602082015260408301516040820152606083015160608201528091505092915050565b600061012080838503121561273b578182fd5b61274481612f90565b9050612750848461240c565b815261275f84602085016124f4565b6020820152604083015160408201526060830151606082015261278584608085016124dc565b60808201526127978460a0850161240c565b60a08201526127a98460c085016124c8565b60c082015260e08381015190820152610100928301519281019290925250919050565b6000606082840312156127dd578081fd5b6127e76060612f90565b8251815260208301516020820152604083015160408201528091505092915050565b60008060006060848603121561281d578081fd5b835161282881612fff565b602085015190935061283981612fff565b604085015190925063ffffffff81168114612852578182fd5b809150509250925092565b60006020828403121561286e578081fd5b5051919050565b6000806000806080858703121561288a578182fd5b84519350602085015161289c81612fe7565b604086015190935067ffffffffffffffff8111156128b8578283fd5b6128c487828801612460565b606096909601519497939650505050565b6000602082840312156128e6578081fd5b815160ff81168114610c3a578182fd5b6001600160a01b03169052565b6000815180845260208085018081965082840281019150828601855b85811015612a6557828403895281516102a081518652868201518787015260408083015161294f828901826128f6565b5050606080830151612963828901826128f6565b5050608080830151612977828901826128f6565b505060a080830151828289015261299083890182612b7c565b9250505060c080830151878303828901526129ab8382612b7c565b9250505060e0808301518188015250610100808301518188015250610120808301516129d9828901826128f6565b50506101408281015190870152610160808301519087015261018080830151908701526101a080830151908701526101c080830151908701526101e080830151908701526102008083015190870152610220808301519087015261024080830151908701526102608083015190870152610280918201519190950152978401979084019060010161291f565b5091979650505050505050565b6000815180845260208085018081965082840281019150828601855b85811015612a6557828403895281516101a0815186528682015187870152604080830151612abe828901826128f6565b5050606080830151612ad2828901826128f6565b5050608080830151612ae6828901826128f6565b505060a0808301518282890152612aff83890182612b7c565b9250505060c08083015187830382890152612b1a8382612b7c565b9250505060e080830151818801525061010080830151818801525061012080830151612b48828901826128f6565b5050610140828101519087015261016080830151908701526101809182015191909501529784019790840190600101612a8e565b60008151808452612b94816020860160208601612fb7565b601f01601f19169290920160200192915050565b60008251612bba818460208701612fb7565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b60208082528251828201819052600091906040908185019080840286018301878501865b83811015612d5d57603f1989840301855281516102a081518552888201518986015287820151612c48898701826128f6565b50606080830151612c5b828801826128f6565b5050608080830151612c6f828801826128f6565b505060a0808301518282880152612c8883880182612b7c565b9250505060c08083015186830382880152612ca38382612b7c565b9250505060e080830151818701525061010080830151818701525061012080830151612cd1828801826128f6565b50506101408281015190860152610160808301519086015261018080830151908601526101a080830151908601526101c080830151908601526101e0808301519086015261020080830151908601526102208083015190860152610240808301519086015261026080830151908601526102809182015191909401529386019390860190600101612c16565b509098975050505050505050565b600060208252610c3a6020830184612a72565b602080825260169082015275536166654d6174683a20416464204f766572666c6f7760501b604082015260600190565b60208082526019908201527f4661726d4c656e7356323a204f6e6c7920666f7220424d434a00000000000000604082015260600190565b602080825260139082015272536166654d6174683a20556e646572666c6f7760681b604082015260600190565b60208082526022908201527f4661726d4c656e7356323a206f6e6c7920666f72204d43563220616e64204d43604082015261563360f01b606082015260800190565b602080825260159082015274536166654d6174683a20446976206279205a65726f60581b604082015260600190565b602080825260169082015275536166654d6174683a204d756c204f766572666c6f7760501b604082015260600190565b60006020825282516020830152602083015160408301526040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015160e083015260e08301516101008181850152808501519150506101606101208181860152612f29610180860184612a72565b9250808601519050601f19610140818786030181880152612f4a8584612a72565b908801518782039092018488015293509050612f668382612903565b9695505050505050565b90815260200190565b9182526001600160a01b0316602082015260400190565b60405181810167ffffffffffffffff81118282101715612faf57600080fd5b604052919050565b60005b83811015612fd2578181015183820152602001612fba565b83811115612fe1576000848401525b50505050565b6001600160a01b0381168114612ffc57600080fd5b50565b6001600160701b0381168114612ffc57600080fdfea26469706673582212203983aa55900a9760eadb8c17e41a9090e6945d3e4e8842df70b5c141f517dd2c64736f6c634300060c0033", + "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100f55760003560e01c80638a38466e11610097578063cff5dd3311610066578063cff5dd33146101b0578063d02641a0146101b8578063eee5c276146101d8578063f97a496c146101eb576100f5565b80638a38466e146101605780639bbf1deb14610168578063b985a3a014610188578063ce7a198914610190576100f5565b806335541641116100d357806335541641146101285780634e57afe014610148578063685f02e71461015057806387dabe4614610158576100f5565b80630d1dcd9a146100fa578063117be4c2146101185780632c9e2b0514610120575b600080fd5b6101026101f3565b60405161010f9190612bc4565b60405180910390f35b610102610217565b61010261023b565b61013b610136366004612543565b61025f565b60405161010f9190612eb3565b6101026106f2565b610102610716565b61010261073a565b61010261075e565b61017b610176366004612650565b610782565b60405161010f9190612d6b565b61010261083b565b6101a361019e3660046125ed565b61085f565b60405161010f9190612bf2565b610102610918565b6101cb6101c636600461250b565b61093c565b60405161010f9190612f70565b6101cb6101e636600461250b565b61096b565b6101cb61097c565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b61026761219a565b61026f61219a565b600061027961098b565b90506000670de0b6b3a76400006102b9836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b90610c41565b816102c057fe5b838552046020808501829052604080516317caf6f160e01b815290519293506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926317caf6f192600480840193919291829003018186803b15801561032d57600080fd5b505afa158015610341573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610365919061285d565b8360400181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156103c757600080fd5b505afa1580156103db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ff919061285d565b8360a00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561046157600080fd5b505afa158015610475573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610499919061285d565b8360600181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b1580156104fb57600080fd5b505afa15801561050f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610533919061285d565b8360c00181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b15801561059557600080fd5b505afa1580156105a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105cd919061285d565b8360800181815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b15801561062f57600080fd5b505afa158015610643573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610667919061285d565b60e08401526106987f0000000000000000000000000000000000000000000000000000000000000000838d8d610c78565b6101008401526106ca7f0000000000000000000000000000000000000000000000000000000000000000838b8b610c78565b6101208401526106dd8282878a8a610ea8565b61014084015250909998505050505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b031614806107f557507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b0316145b61081a5760405162461bcd60e51b815260040161081190612e12565b60405180910390fd5b600061082461098b565b905061083285828686610c78565b95945050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60607f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b0316146108b25760405162461bcd60e51b815260040161081190612dae565b60006108bc61098b565b90506000670de0b6b3a76400006108f6836102b37f0000000000000000000000000000000000000000000000000000000000000000610a86565b816108fd57fe5b04905061090d8282888888610ea8565b979650505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000670de0b6b3a764000061095b61095261098b565b6102b385610a86565b8161096257fe5b0490505b919050565b600061097682610a86565b92915050565b600061098661098b565b905090565b60006003610a796109dc7f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006112b5565b610a73610a297f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006112b5565b610a737f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006112b5565b9061145a565b81610a8057fe5b04905090565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161415610ad15750670de0b6b3a7640000610966565b60405163e6a4390560e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e6a4390590610b429086907f000000000000000000000000000000000000000000000000000000000000000090600401612bd8565b60206040518083038186803b158015610b5a57600080fd5b505afa158015610b6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b929190612527565b90506001600160a01b038116610bac576000915050610966565b610c3a81826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015610be957600080fd5b505afa158015610bfd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c219190612527565b6001600160a01b0316856001600160a01b0316146112b5565b9392505050565b6000811580610c5c57505080820282828281610c5957fe5b04145b6109765760405162461bcd60e51b815260040161081190612e83565b606081818167ffffffffffffffff81118015610c9357600080fd5b50604051908082528060200260200182016040528015610ccd57816020015b610cba6121f4565b815260200190600190039081610cb25790505b5090506000876001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610d0b57600080fd5b505afa158015610d1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d43919061285d565b90506000886001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610d8057600080fd5b505afa158015610d94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610db8919061285d565b905060005b84811015610e9a576000888883818110610dd357fe5b905060200201359050610de4612280565b604051631526fe2760e01b81526001600160a01b038d1690631526fe2790610e10908590600401612f70565b60806040518083038186803b158015610e2857600080fd5b505afa158015610e3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6091906126d6565b9050610e798c8c84846000015185602001518a8a61147d565b868481518110610e8557fe5b60209081029190910101525050600101610dbd565b509198975050505050505050565b6060610eb26122b1565b60405180606001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166317caf6f16040518163ffffffff1660e01b815260040160206040518083038186803b158015610f4557600080fd5b505afa158015610f59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f7d919061285d565b81526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ca418d236040518163ffffffff1660e01b815260040160206040518083038186803b158015610fdb57600080fd5b505afa158015610fef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611013919061285d565b905290508260608167ffffffffffffffff8111801561103157600080fd5b5060405190808252806020026020018201604052801561106b57816020015b6110586122db565b8152602001906001900390816110505790505b50905060005b828110156112a857600087878381811061108757fe5b90506020020135905061109861239f565b8551604051631526fe2760e01b81526001600160a01b0390911690631526fe27906110c7908590600401612f70565b6101206040518083038186803b1580156110e057600080fd5b505afa1580156110f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111189190612728565b90506111226123eb565b86516040516393f1a40b60e01b81526001600160a01b03909116906393f1a40b906111539086908f90600401612f79565b60606040518083038186803b15801561116b57600080fd5b505afa15801561117f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a391906127cc565b9050828585815181106111b257fe5b602090810291909101015152865185518690869081106111ce57fe5b602002602001015161012001906001600160a01b031690816001600160a01b031681525050866020015185858151811061120457fe5b6020026020010151610160018181525050866040015185858151811061122657fe5b60200260200101516101800181815250508b85858151811061124457fe5b602002602001015161020001818152505061129d8d670de0b6b3a76400006112798f8b60400151610c4190919063ffffffff16565b8161128057fe5b048d88888151811061128e57fe5b602002602001015186866117c7565b505050600101611071565b5098975050505050505050565b6000806000846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b1580156112f357600080fd5b505afa158015611307573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061132b9190612809565b506001600160701b031691506001600160701b0316915060006113c6866001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561138057600080fd5b505afa158015611394573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b89190612527565b6001600160a01b0316611c96565b60ff1690506000611409876001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561138057600080fd5b60ff16905085156114475761143c83611436866114318661142b87601261145a565b90611d57565b611d7a565b90611d96565b945050505050610976565b61143c84611436856114318561142b8860125b818101818110156109765760405162461bcd60e51b815260040161081190612d7e565b6114856121f4565b6000856001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156114c057600080fd5b505afa1580156114d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114f891906128d5565b60ff169050600061157c876001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561153b57600080fd5b505afa15801561154f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611573919061285d565b83601203611d7a565b90506000611608886001600160a01b03166370a082318d6040518263ffffffff1660e01b81526004016115af9190612bc4565b60206040518083038186803b1580156115c757600080fd5b505afa1580156115db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ff919061285d565b84601203611d7a565b90506000670de0b6b3a76400006116228c6102b38c611dc8565b8161162957fe5b0490506000896001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561166757600080fd5b505afa15801561167b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061169f9190612527565b905060008a6001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b1580156116dc57600080fd5b505afa1580156116f0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117149190612527565b9050604051806101a001604052808d81526020018b81526020018c6001600160a01b03168152602001836001600160a01b03168152602001826001600160a01b0316815260200161176d846001600160a01b03166120c7565b8152602001611784836001600160a01b03166120c7565b81526020018481526020018681526020018f6001600160a01b031681526020018581526020018a8152602001898152509650505050505050979650505050505050565b6000826000015190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b15801561180b57600080fd5b505afa15801561181f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118439190612527565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b15801561188057600080fd5b505afa158015611894573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118b89190612527565b6020808701516001600160601b0316908801526001600160a01b0380851660408901528381166060890181905290821660808901529091506118f9906120c7565b60a08701526119106001600160a01b0382166120c7565b60c0870152670de0b6b3a764000061192b8a6102b386611dc8565b8161193257fe5b048660e0018181525050826001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561197557600080fd5b505afa158015611989573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119ad919061285d565b61010080880191909152850151610140870152835161022087015260c085015163ffffffff166101e0870152855160405160016232bd9d60e01b031981526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163ffcd426391611a2b91908b90600401612f79565b60006040518083038186803b158015611a4357600080fd5b505afa158015611a57573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611a7f9190810190612875565b50505061024087015250505061010082015115801590611aa3575061010083015115155b8015611ab3575061016083015115155b8015611ac2575060e083015115155b15611c8e576000836101600151611af76301e133806102b386602001516001600160601b03168a610c4190919063ffffffff16565b81611afe57fe5b0490506000846101000151611b258661014001518760e00151610c4190919063ffffffff16565b81611b2c57fe5b04905080611b3b575050611c8e565b61271081611b6c670de0b6b3a76400006102b38860c0015163ffffffff166127100387610c4190919063ffffffff16565b81611b7357fe5b0481611b7b57fe5b046101a086015260e084015115611c8b5761271081611bb9670de0b6b3a76400006102b38860c0015163ffffffff1687610c4190919063ffffffff16565b81611bc057fe5b0481611bc857fe5b046101c0860152825115801590611be25750604083015115155b15611c8b5761010084015160e0860151845160009291611c029190610c41565b81611c0957fe5b04905061271081611c49670de0b6b3a76400006102b38960e001516114368a604001516102b38d60c0015163ffffffff168c610c4190919063ffffffff16565b81611c5057fe5b0481611c5857fe5b0461026087015260e08501516040850151611c7b90670de0b6b3a7640000610c41565b81611c8257fe5b04610280870152505b50505b505050505050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b179052905160009182916060916001600160a01b03861691611cdd9190612ba8565b600060405180830381855afa9150503d8060008114611d18576040519150601f19603f3d011682016040523d82523d6000602084013e611d1d565b606091505b5091509150818015611d30575080516020145b611d3b576012611d4f565b80806020019051810190611d4f91906128d5565b949350505050565b808203828111156109765760405162461bcd60e51b815260040161081190612de5565b600081611d88575081610976565b610c3a83600a84900a610c41565b6000808211611db75760405162461bcd60e51b815260040161081190612e54565b818381611dc057fe5b049392505050565b6000807f00000000000000000000000000000000000000000000000000000000000000009050600080846001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015611e2a57600080fd5b505afa158015611e3e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e629190612809565b506001600160701b031691506001600160701b031691506000856001600160a01b0316630dfe16816040518163ffffffff1660e01b815260040160206040518083038186803b158015611eb457600080fd5b505afa158015611ec8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611eec9190612527565b90506000866001600160a01b031663d21220a76040518163ffffffff1660e01b815260040160206040518083038186803b158015611f2957600080fd5b505afa158015611f3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f619190612527565b90506000611f77836001600160a01b0316611c96565b60ff1690506000611f90836001600160a01b0316611c96565b60ff169050611fa486611431601285611d57565b9550611fb585611431601284611d57565b9450600080886001600160a01b0316866001600160a01b03161415611ff157670de0b6b3a76400009150611fea8b60016112b5565b9050612090565b886001600160a01b0316856001600160a01b03161415612028576120168b60006112b5565b9150670de0b6b3a76400009050612090565b61203186610a86565b915061203c85610a86565b90508161207357670de0b6b3a764000061205b60026102b38a85610c41565b8161206257fe5b049950505050505050505050610966565b8061209057670de0b6b3a764000061205b60026102b38b86610c41565b670de0b6b3a76400006120b06120a68984610c41565b610a738b86610c41565b816120b757fe5b049b9a5050505050505050505050565b60408051600481526024810182526020810180516001600160e01b03166395d89b4160e01b179052905160609160009183916001600160a01b0386169161210e9190612ba8565b600060405180830381855afa9150503d8060008114612149576040519150601f19603f3d011682016040523d82523d6000602084013e61214e565b606091505b5091509150818015612161575060008151115b61218657604051806040016040528060038152602001623f3f3f60e81b815250611d4f565b80806020019051810190611d4f91906126a3565b60405180610160016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016060815260200160608152602001606081525090565b604051806101a00160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806080016040528060006001600160a01b031681526020016000815260200160008152602001600081525090565b604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b604051806102a00160405280600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016060815260200160608152602001600081526020016000815260200160006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915290565b60405180606001604052806000815260200160008152602001600081525090565b805161097681612fe7565b60008083601f840112612428578182fd5b50813567ffffffffffffffff81111561243f578182fd5b602083019150836020808302850101111561245957600080fd5b9250929050565b600082601f830112612470578081fd5b815167ffffffffffffffff811115612486578182fd5b612499601f8201601f1916602001612f90565b91508082528360208285010111156124b057600080fd5b6124c1816020840160208601612fb7565b5092915050565b805163ffffffff8116811461097657600080fd5b805167ffffffffffffffff8116811461097657600080fd5b80516001600160601b038116811461097657600080fd5b60006020828403121561251c578081fd5b8135610c3a81612fe7565b600060208284031215612538578081fd5b8151610c3a81612fe7565b60008060008060008060006080888a03121561255d578283fd5b873567ffffffffffffffff80821115612574578485fd5b6125808b838c01612417565b909950975060208a0135915080821115612598578485fd5b6125a48b838c01612417565b909750955060408a01359150808211156125bc578485fd5b506125c98a828b01612417565b90945092505060608801356125dd81612fe7565b8091505092959891949750929550565b60008060008060608587031215612602578384fd5b843561260d81612fe7565b9350602085013561261d81612fe7565b9250604085013567ffffffffffffffff811115612638578283fd5b61264487828801612417565b95989497509550505050565b600080600060408486031215612664578283fd5b833561266f81612fe7565b9250602084013567ffffffffffffffff81111561268a578283fd5b61269686828701612417565b9497909650939450505050565b6000602082840312156126b4578081fd5b815167ffffffffffffffff8111156126ca578182fd5b611d4f84828501612460565b6000608082840312156126e7578081fd5b6126f16080612f90565b82516126fc81612fe7565b808252506020830151602082015260408301516040820152606083015160608201528091505092915050565b600061012080838503121561273b578182fd5b61274481612f90565b9050612750848461240c565b815261275f84602085016124f4565b6020820152604083015160408201526060830151606082015261278584608085016124dc565b60808201526127978460a0850161240c565b60a08201526127a98460c085016124c8565b60c082015260e08381015190820152610100928301519281019290925250919050565b6000606082840312156127dd578081fd5b6127e76060612f90565b8251815260208301516020820152604083015160408201528091505092915050565b60008060006060848603121561281d578081fd5b835161282881612fff565b602085015190935061283981612fff565b604085015190925063ffffffff81168114612852578182fd5b809150509250925092565b60006020828403121561286e578081fd5b5051919050565b6000806000806080858703121561288a578182fd5b84519350602085015161289c81612fe7565b604086015190935067ffffffffffffffff8111156128b8578283fd5b6128c487828801612460565b606096909601519497939650505050565b6000602082840312156128e6578081fd5b815160ff81168114610c3a578182fd5b6001600160a01b03169052565b6000815180845260208085018081965082840281019150828601855b85811015612a6557828403895281516102a081518652868201518787015260408083015161294f828901826128f6565b5050606080830151612963828901826128f6565b5050608080830151612977828901826128f6565b505060a080830151828289015261299083890182612b7c565b9250505060c080830151878303828901526129ab8382612b7c565b9250505060e0808301518188015250610100808301518188015250610120808301516129d9828901826128f6565b50506101408281015190870152610160808301519087015261018080830151908701526101a080830151908701526101c080830151908701526101e080830151908701526102008083015190870152610220808301519087015261024080830151908701526102608083015190870152610280918201519190950152978401979084019060010161291f565b5091979650505050505050565b6000815180845260208085018081965082840281019150828601855b85811015612a6557828403895281516101a0815186528682015187870152604080830151612abe828901826128f6565b5050606080830151612ad2828901826128f6565b5050608080830151612ae6828901826128f6565b505060a0808301518282890152612aff83890182612b7c565b9250505060c08083015187830382890152612b1a8382612b7c565b9250505060e080830151818801525061010080830151818801525061012080830151612b48828901826128f6565b5050610140828101519087015261016080830151908701526101809182015191909501529784019790840190600101612a8e565b60008151808452612b94816020860160208601612fb7565b601f01601f19169290920160200192915050565b60008251612bba818460208701612fb7565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b60208082528251828201819052600091906040908185019080840286018301878501865b83811015612d5d57603f1989840301855281516102a081518552888201518986015287820151612c48898701826128f6565b50606080830151612c5b828801826128f6565b5050608080830151612c6f828801826128f6565b505060a0808301518282880152612c8883880182612b7c565b9250505060c08083015186830382880152612ca38382612b7c565b9250505060e080830151818701525061010080830151818701525061012080830151612cd1828801826128f6565b50506101408281015190860152610160808301519086015261018080830151908601526101a080830151908601526101c080830151908601526101e0808301519086015261020080830151908601526102208083015190860152610240808301519086015261026080830151908601526102809182015191909401529386019390860190600101612c16565b509098975050505050505050565b600060208252610c3a6020830184612a72565b602080825260169082015275536166654d6174683a20416464204f766572666c6f7760501b604082015260600190565b60208082526019908201527f4661726d4c656e7356323a204f6e6c7920666f7220424d434a00000000000000604082015260600190565b602080825260139082015272536166654d6174683a20556e646572666c6f7760681b604082015260600190565b60208082526022908201527f4661726d4c656e7356323a206f6e6c7920666f72204d43563220616e64204d43604082015261563360f01b606082015260800190565b602080825260159082015274536166654d6174683a20446976206279205a65726f60581b604082015260600190565b602080825260169082015275536166654d6174683a204d756c204f766572666c6f7760501b604082015260600190565b60006020825282516020830152602083015160408301526040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015160e083015260e08301516101008181850152808501519150506101606101208181860152612f29610180860184612a72565b9250808601519050601f19610140818786030181880152612f4a8584612a72565b908801518782039092018488015293509050612f668382612903565b9695505050505050565b90815260200190565b9182526001600160a01b0316602082015260400190565b60405181810167ffffffffffffffff81118282101715612faf57600080fd5b604052919050565b60005b83811015612fd2578181015183820152602001612fba565b83811115612fe1576000848401525b50505050565b6001600160a01b0381168114612ffc57600080fd5b50565b6001600160701b0381168114612ffc57600080fdfea26469706673582212203983aa55900a9760eadb8c17e41a9090e6945d3e4e8842df70b5c141f517dd2c64736f6c634300060c0033", "devdoc": { "kind": "dev", "methods": { diff --git a/deployments/rinkeby/solcInputs/05be5b065453cde7967331fef060caff.json b/deployments/rinkeby/solcInputs/05be5b065453cde7967331fef060caff.json new file mode 100644 index 00000000..40b2e0aa --- /dev/null +++ b/deployments/rinkeby/solcInputs/05be5b065453cde7967331fef060caff.json @@ -0,0 +1,274 @@ +{ + "language": "Solidity", + "sources": { + "contracts/BoostedMasterChefJoe.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/proxy/Initializable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol\";\nimport \"./interfaces/IERC20.sol\";\nimport \"./interfaces/IMasterChefJoe.sol\";\nimport \"./interfaces/IRewarder.sol\";\nimport \"./libraries/BoringJoeERC20.sol\";\nimport \"./traderjoe/libraries/Math.sol\";\n\n/// @notice The (older) MasterChefJoeV2 contract gives out a constant number of JOE\n/// tokens per block. It is the only address with minting rights for JOE. The idea\n/// for this BoostedMasterChefJoe (BMCJ) contract is therefore to be the owner of a\n/// dummy token that is deposited into the MasterChefJoeV2 (MCJV2) contract. The\n/// allocation point for this pool on MCJV2 is the total allocation point for all\n/// pools on BMCJ.\n///\n/// This MasterChef also skews how many rewards users receive, it does this by\n/// modifying the algorithm that calculates how many tokens are rewarded to\n/// depositors. Whereas MasterChef calculates rewards based on emission rate and\n/// total liquidity, this version uses adjusted parameters to this calculation.\n///\n/// A users `boostedAmount` (liquidity multiplier) is calculated by the actual supplied\n/// liquidity multiplied by a boost factor. The boost factor is calculated by the\n/// amount of veJOE held by the user over the total veJOE amount held by all pool\n/// participants. Total liquidity is the sum of all boosted liquidity.\ncontract BoostedMasterChefJoe is Initializable, OwnableUpgradeable, ReentrancyGuardUpgradeable {\n using BoringJoeERC20 for IERC20;\n using SafeMathUpgradeable for uint256;\n\n /// @notice Info of each BMCJ user\n /// `amount` LP token amount the user has provided\n /// `rewardDebt` The amount of JOE entitled to the user\n /// `factor` the users factor, use _getUserFactor\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n uint256 factor;\n }\n\n /// @notice Info of each BMCJ pool\n /// `allocPoint` The amount of allocation points assigned to the pool\n /// Also known as the amount of JOE to distribute per block\n struct PoolInfo {\n // Address are stored in 160 bits, so we store allocPoint in 96 bits to\n // optimize storage (160 + 96 = 256)\n IERC20 lpToken;\n uint96 allocPoint;\n uint256 accJoePerShare;\n uint256 accJoePerFactorPerShare;\n // Address are stored in 160 bits, so we store lastRewardTimestamp in 64 bits and\n // veJoeShareBp in 32 bits to optimize storage (160 + 64 + 32 = 256)\n uint64 lastRewardTimestamp;\n IRewarder rewarder;\n // Share of the reward to distribute to veJoe holders\n uint32 veJoeShareBp;\n // The sum of all veJoe held by users participating in this farm\n // This value is updated when\n // - A user enter/leaves a farm\n // - A user claims veJOE\n // - A user unstakes JOE\n uint256 totalFactor;\n // The total LP supply of the farm\n // This is the sum of all users boosted amounts in the farm. Updated when\n // someone deposits or withdraws.\n // This is used instead of the usual `lpToken.balanceOf(address(this))` for security reasons\n uint256 totalLpSupply;\n }\n\n /// @notice Address of MCJV2 contract\n IMasterChefJoe public MASTER_CHEF_V2;\n /// @notice Address of JOE contract\n IERC20 public JOE;\n /// @notice Address of veJOE contract\n IERC20 public VEJOE;\n /// @notice The index of BMCJ master pool in MCJV2\n uint256 public MASTER_PID;\n\n /// @notice Info of each BMCJ pool\n PoolInfo[] public poolInfo;\n /// @dev Maps an address to a bool to assert that a token isn't added twice\n mapping(IERC20 => bool) private checkPoolDuplicate;\n\n /// @notice Info of each user that stakes LP tokens\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n /// @dev Total allocation points. Must be the sum of all allocation points in all pools\n uint256 public totalAllocPoint;\n uint256 private ACC_TOKEN_PRECISION;\n\n /// @dev Amount of claimable Joe the user has, this is required as we\n /// need to update rewardDebt after a token operation but we don't\n /// want to send a reward at this point. This amount gets added onto\n /// the pending amount when a user claims\n mapping(uint256 => mapping(address => uint256)) public claimableJoe;\n\n event Add(\n uint256 indexed pid,\n uint256 allocPoint,\n uint256 veJoeShareBp,\n IERC20 indexed lpToken,\n IRewarder indexed rewarder\n );\n event Set(\n uint256 indexed pid,\n uint256 allocPoint,\n uint256 veJoeShareBp,\n IRewarder indexed rewarder,\n bool overwrite\n );\n event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\n event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event UpdatePool(\n uint256 indexed pid,\n uint256 lastRewardTimestamp,\n uint256 lpSupply,\n uint256 accJoePerShare,\n uint256 accJoePerFactorPerShare\n );\n event Harvest(address indexed user, uint256 indexed pid, uint256 amount);\n event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event Init(uint256 amount);\n\n /// @param _MASTER_CHEF_V2 The MCJV2 contract address\n /// @param _joe The JOE token contract address\n /// @param _veJoe The veJOE token contract address\n /// @param _MASTER_PID The pool ID of the dummy token on the base MCJV2 contract\n function initialize(\n IMasterChefJoe _MASTER_CHEF_V2,\n IERC20 _joe,\n IERC20 _veJoe,\n uint256 _MASTER_PID\n ) public initializer {\n __Ownable_init();\n MASTER_CHEF_V2 = _MASTER_CHEF_V2;\n JOE = _joe;\n VEJOE = _veJoe;\n MASTER_PID = _MASTER_PID;\n\n ACC_TOKEN_PRECISION = 1e18;\n }\n\n /// @notice Deposits a dummy token to `MASTER_CHEF_V2` MCJV2. This is required because MCJV2\n /// holds the minting rights for JOE. Any balance of transaction sender in `_dummyToken` is transferred.\n /// The allocation point for the pool on MCJV2 is the total allocation point for all pools that receive\n /// double incentives.\n /// @param _dummyToken The address of the ERC-20 token to deposit into MCJV2.\n function init(IERC20 _dummyToken) external onlyOwner {\n require(\n _dummyToken.balanceOf(address(MASTER_CHEF_V2)) == 0,\n \"BoostedMasterChefJoe: Already has a balance of dummy token\"\n );\n uint256 balance = _dummyToken.balanceOf(_msgSender());\n require(balance != 0, \"BoostedMasterChefJoe: Balance must exceed 0\");\n _dummyToken.safeTransferFrom(_msgSender(), address(this), balance);\n _dummyToken.approve(address(MASTER_CHEF_V2), balance);\n MASTER_CHEF_V2.deposit(MASTER_PID, balance);\n emit Init(balance);\n }\n\n /// @notice Add a new LP to the pool. Can only be called by the owner.\n /// @param _allocPoint AP of the new pool.\n /// @param _veJoeShareBp Share of rewards allocated in proportion to user's liquidity\n /// and veJoe balance\n /// @param _lpToken Address of the LP ERC-20 token.\n /// @param _rewarder Address of the rewarder delegate.\n function add(\n uint96 _allocPoint,\n uint32 _veJoeShareBp,\n IERC20 _lpToken,\n IRewarder _rewarder\n ) external onlyOwner {\n require(!checkPoolDuplicate[_lpToken], \"BoostedMasterChefJoe: LP already added\");\n require(_veJoeShareBp <= 10_000, \"BoostedMasterChefJoe: veJoeShareBp needs to be lower than 10000\");\n require(poolInfo.length <= 50, \"BoostedMasterChefJoe: Too many pools\");\n checkPoolDuplicate[_lpToken] = true;\n // Sanity check to ensure _lpToken is an ERC20 token\n _lpToken.balanceOf(address(this));\n // Sanity check if we add a rewarder\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(address(0), 0);\n }\n\n massUpdatePools();\n\n totalAllocPoint = totalAllocPoint.add(_allocPoint);\n\n poolInfo.push(\n PoolInfo({\n lpToken: _lpToken,\n allocPoint: _allocPoint,\n accJoePerShare: 0,\n accJoePerFactorPerShare: 0,\n lastRewardTimestamp: uint64(block.timestamp),\n rewarder: _rewarder,\n veJoeShareBp: _veJoeShareBp,\n totalFactor: 0,\n totalLpSupply: 0\n })\n );\n emit Add(poolInfo.length - 1, _allocPoint, _veJoeShareBp, _lpToken, _rewarder);\n }\n\n /// @notice Update the given pool's JOE allocation point and `IRewarder` contract. Can only be called by the owner.\n /// @param _pid The index of the pool. See `poolInfo`\n /// @param _allocPoint New AP of the pool\n /// @param _veJoeShareBp Share of rewards allocated in proportion to user's liquidity\n /// and veJoe balance\n /// @param _rewarder Address of the rewarder delegate\n /// @param _overwrite True if _rewarder should be `set`. Otherwise `_rewarder` is ignored\n function set(\n uint256 _pid,\n uint96 _allocPoint,\n uint32 _veJoeShareBp,\n IRewarder _rewarder,\n bool _overwrite\n ) external onlyOwner {\n require(_veJoeShareBp <= 10_000, \"BoostedMasterChefJoe: veJoeShareBp needs to be lower than 10000\");\n massUpdatePools();\n\n PoolInfo storage pool = poolInfo[_pid];\n totalAllocPoint = totalAllocPoint.add(_allocPoint).sub(pool.allocPoint);\n pool.allocPoint = _allocPoint;\n pool.veJoeShareBp = _veJoeShareBp;\n if (_overwrite) {\n if (address(_rewarder) != address(0)) {\n // Sanity check\n _rewarder.onJoeReward(address(0), 0);\n }\n pool.rewarder = _rewarder;\n }\n\n emit Set(_pid, _allocPoint, _veJoeShareBp, _overwrite ? _rewarder : pool.rewarder, _overwrite);\n }\n\n /// @notice Deposit LP tokens to BMCJ for JOE allocation\n /// @param _pid The index of the pool. See `poolInfo`\n /// @param _amount LP token amount to deposit\n function deposit(uint256 _pid, uint256 _amount) external nonReentrant {\n harvestFromMasterChef();\n updatePool(_pid);\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_msgSender()];\n\n // Pay a user any pending rewards\n if (user.amount != 0) {\n _harvestJoe(user, pool, _pid);\n }\n\n uint256 balanceBefore = pool.lpToken.balanceOf(address(this));\n pool.lpToken.safeTransferFrom(_msgSender(), address(this), _amount);\n uint256 receivedAmount = pool.lpToken.balanceOf(address(this)).sub(balanceBefore);\n\n _updateUserAndPool(user, pool, receivedAmount, true);\n\n IRewarder _rewarder = pool.rewarder;\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(_msgSender(), user.amount);\n }\n emit Deposit(_msgSender(), _pid, receivedAmount);\n }\n\n /// @notice Withdraw LP tokens from BMCJ\n /// @param _pid The index of the pool. See `poolInfo`\n /// @param _amount LP token amount to withdraw\n function withdraw(uint256 _pid, uint256 _amount) external nonReentrant {\n harvestFromMasterChef();\n updatePool(_pid);\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_msgSender()];\n require(user.amount >= _amount, \"BoostedMasterChefJoe: withdraw not good\");\n\n if (user.amount != 0) {\n _harvestJoe(user, pool, _pid);\n }\n\n _updateUserAndPool(user, pool, _amount, false);\n\n pool.lpToken.safeTransfer(_msgSender(), _amount);\n\n IRewarder _rewarder = pool.rewarder;\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(_msgSender(), user.amount);\n }\n emit Withdraw(_msgSender(), _pid, _amount);\n }\n\n /// @notice Updates factor after after a veJoe token operation.\n /// This function needs to be called by the veJoe contract after\n /// every mint / burn.\n /// @param _user The users address we are updating\n /// @param _newVeJoeBalance The new balance of the users veJoe\n function updateFactor(address _user, uint256 _newVeJoeBalance) external {\n require(_msgSender() == address(VEJOE), \"BoostedMasterChefJoe: Caller not veJOE\");\n uint256 len = poolInfo.length;\n uint256 _ACC_TOKEN_PRECISION = ACC_TOKEN_PRECISION;\n\n for (uint256 pid; pid < len; ++pid) {\n UserInfo storage user = userInfo[pid][_user];\n\n // Skip if user doesn't have any deposit in the pool\n uint256 amount = user.amount;\n if (amount == 0) {\n continue;\n }\n\n PoolInfo storage pool = poolInfo[pid];\n\n updatePool(pid);\n uint256 oldFactor = user.factor;\n (uint256 accJoePerShare, uint256 accJoePerFactorPerShare) = (\n pool.accJoePerShare,\n pool.accJoePerFactorPerShare\n );\n uint256 pending = amount\n .mul(accJoePerShare)\n .add(oldFactor.mul(accJoePerFactorPerShare))\n .div(_ACC_TOKEN_PRECISION)\n .sub(user.rewardDebt);\n\n // Increase claimableJoe\n claimableJoe[pid][_user] = claimableJoe[pid][_user].add(pending);\n\n // Update users veJoeBalance\n uint256 newFactor = _getUserFactor(amount, _newVeJoeBalance);\n user.factor = newFactor;\n pool.totalFactor = pool.totalFactor.add(newFactor).sub(oldFactor);\n\n user.rewardDebt = amount.mul(accJoePerShare).add(newFactor.mul(accJoePerFactorPerShare)).div(\n _ACC_TOKEN_PRECISION\n );\n\n // Update the pool total veJoe\n }\n }\n\n /// @notice Withdraw without caring about rewards (EMERGENCY ONLY)\n /// @param _pid The index of the pool. See `poolInfo`\n function emergencyWithdraw(uint256 _pid) external nonReentrant {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_msgSender()];\n\n pool.totalFactor = pool.totalFactor.sub(user.factor);\n pool.totalLpSupply = pool.totalLpSupply.sub(user.amount);\n uint256 amount = user.amount;\n user.amount = 0;\n user.rewardDebt = 0;\n user.factor = 0;\n\n IRewarder _rewarder = pool.rewarder;\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(_msgSender(), 0);\n }\n\n // Note: transfer can fail or succeed if `amount` is zero\n pool.lpToken.safeTransfer(_msgSender(), amount);\n emit EmergencyWithdraw(_msgSender(), _pid, amount);\n }\n\n /// @notice Calculates and returns the `amount` of JOE per second\n /// @return amount The amount of JOE emitted per second\n function joePerSec() public view returns (uint256 amount) {\n uint256 total = 1000;\n uint256 lpPercent = total.sub(MASTER_CHEF_V2.devPercent()).sub(MASTER_CHEF_V2.treasuryPercent()).sub(\n MASTER_CHEF_V2.investorPercent()\n );\n uint256 lpShare = MASTER_CHEF_V2.joePerSec().mul(lpPercent).div(total);\n amount = lpShare.mul(MASTER_CHEF_V2.poolInfo(MASTER_PID).allocPoint).div(MASTER_CHEF_V2.totalAllocPoint());\n }\n\n /// @notice View function to see pending JOE on frontend\n /// @param _pid The index of the pool. See `poolInfo`\n /// @param _user Address of user\n /// @return pendingJoe JOE reward for a given user.\n /// @return bonusTokenAddress The address of the bonus reward.\n /// @return bonusTokenSymbol The symbol of the bonus token.\n /// @return pendingBonusToken The amount of bonus rewards pending.\n function pendingTokens(uint256 _pid, address _user)\n external\n view\n returns (\n uint256 pendingJoe,\n address bonusTokenAddress,\n string memory bonusTokenSymbol,\n uint256 pendingBonusToken\n )\n {\n PoolInfo memory pool = poolInfo[_pid];\n UserInfo memory user = userInfo[_pid][_user];\n uint256 accJoePerShare = pool.accJoePerShare;\n uint256 accJoePerFactorPerShare = pool.accJoePerFactorPerShare;\n\n if (block.timestamp > pool.lastRewardTimestamp && pool.totalLpSupply != 0 && pool.allocPoint != 0) {\n uint256 secondsElapsed = block.timestamp - pool.lastRewardTimestamp;\n uint256 joeReward = secondsElapsed.mul(joePerSec()).mul(pool.allocPoint).div(totalAllocPoint);\n accJoePerShare = accJoePerShare.add(\n joeReward.mul(ACC_TOKEN_PRECISION).mul(10_000 - pool.veJoeShareBp).div(pool.totalLpSupply.mul(10_000))\n );\n if (pool.veJoeShareBp != 0 && pool.totalFactor != 0) {\n accJoePerFactorPerShare = accJoePerFactorPerShare.add(\n joeReward.mul(ACC_TOKEN_PRECISION).mul(pool.veJoeShareBp).div(pool.totalFactor.mul(10_000))\n );\n }\n }\n\n pendingJoe = (user.amount.mul(accJoePerShare))\n .add(user.factor.mul(accJoePerFactorPerShare))\n .div(ACC_TOKEN_PRECISION)\n .add(claimableJoe[_pid][_user])\n .sub(user.rewardDebt);\n\n // If it's a double reward farm, we return info about the bonus token\n if (address(pool.rewarder) != address(0)) {\n bonusTokenAddress = address(pool.rewarder.rewardToken());\n bonusTokenSymbol = IERC20(bonusTokenAddress).safeSymbol();\n pendingBonusToken = pool.rewarder.pendingTokens(_user);\n }\n }\n\n /// @notice Returns the number of BMCJ pools.\n /// @return pools The amount of pools in this farm\n function poolLength() external view returns (uint256 pools) {\n pools = poolInfo.length;\n }\n\n /// @notice Update reward variables for all pools. Be careful of gas spending!\n function massUpdatePools() public {\n uint256 len = poolInfo.length;\n for (uint256 i = 0; i < len; ++i) {\n updatePool(i);\n }\n }\n\n /// @notice Update reward variables of the given pool\n /// @param _pid The index of the pool. See `poolInfo`\n function updatePool(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n uint256 lastRewardTimestamp = pool.lastRewardTimestamp;\n if (block.timestamp > lastRewardTimestamp) {\n uint256 lpSupply = pool.totalLpSupply;\n uint256 allocPoint = pool.allocPoint;\n // gas opt and prevent div by 0\n if (lpSupply != 0 && allocPoint != 0) {\n uint256 secondsElapsed = block.timestamp - lastRewardTimestamp;\n uint256 veJoeShareBp = pool.veJoeShareBp;\n uint256 totalFactor = pool.totalFactor;\n\n uint256 joeReward = secondsElapsed.mul(joePerSec()).mul(allocPoint).div(totalAllocPoint);\n pool.accJoePerShare = pool.accJoePerShare.add(\n joeReward.mul(ACC_TOKEN_PRECISION).mul(10_000 - veJoeShareBp).div(lpSupply.mul(10_000))\n );\n // If veJoeShareBp is 0, then we don't need to update it\n if (veJoeShareBp != 0 && totalFactor != 0) {\n pool.accJoePerFactorPerShare = pool.accJoePerFactorPerShare.add(\n joeReward.mul(ACC_TOKEN_PRECISION).mul(veJoeShareBp).div(totalFactor.mul(10_000))\n );\n }\n }\n pool.lastRewardTimestamp = uint64(block.timestamp);\n emit UpdatePool(\n _pid,\n pool.lastRewardTimestamp,\n lpSupply,\n pool.accJoePerShare,\n pool.accJoePerFactorPerShare\n );\n }\n }\n\n /// @notice Harvests JOE from `MASTER_CHEF_V2` MCJV2 and pool `MASTER_PID` to this BMCJ contract\n function harvestFromMasterChef() public {\n MASTER_CHEF_V2.deposit(MASTER_PID, 0);\n }\n\n /// @notice Return an user's factor\n /// @param amount The user's amount of liquidity\n /// @param veJoeBalance The user's veJoe balance\n /// @return uint256 The user's factor\n function _getUserFactor(uint256 amount, uint256 veJoeBalance) private pure returns (uint256) {\n return Math.sqrt(amount * veJoeBalance);\n }\n\n /// @notice Updates user and pool infos\n /// @param _user The user that needs to be updated\n /// @param _pool The pool that needs to be updated\n /// @param _amount The amount that was deposited or withdrawn\n /// @param _isDeposit If the action of the user is a deposit\n function _updateUserAndPool(\n UserInfo storage _user,\n PoolInfo storage _pool,\n uint256 _amount,\n bool _isDeposit\n ) private {\n uint256 oldAmount = _user.amount;\n uint256 newAmount = _isDeposit ? oldAmount.add(_amount) : oldAmount.sub(_amount);\n\n if (_amount != 0) {\n _user.amount = newAmount;\n _pool.totalLpSupply = _isDeposit ? _pool.totalLpSupply.add(_amount) : _pool.totalLpSupply.sub(_amount);\n }\n\n uint256 oldFactor = _user.factor;\n uint256 newFactor = _getUserFactor(newAmount, VEJOE.balanceOf(_msgSender()));\n\n if (oldFactor != newFactor) {\n _user.factor = newFactor;\n _pool.totalFactor = _pool.totalFactor.add(newFactor).sub(oldFactor);\n }\n\n _user.rewardDebt = newAmount.mul(_pool.accJoePerShare).add(newFactor.mul(_pool.accJoePerFactorPerShare)).div(\n ACC_TOKEN_PRECISION\n );\n }\n\n /// @notice Harvests user's pending JOE\n /// @dev WARNING this function doesn't update user's rewardDebt,\n /// it still needs to be updated in order for this contract to work properlly\n /// @param _user The user that will harvest its rewards\n /// @param _pool The pool where the user staked and want to harvest its JOE\n /// @param _pid The pid of that pool\n function _harvestJoe(\n UserInfo storage _user,\n PoolInfo storage _pool,\n uint256 _pid\n ) private {\n uint256 pending = (_user.amount.mul(_pool.accJoePerShare))\n .add(_user.factor.mul(_pool.accJoePerFactorPerShare))\n .div(ACC_TOKEN_PRECISION)\n .add(claimableJoe[_pid][_msgSender()])\n .sub(_user.rewardDebt);\n claimableJoe[_pid][_msgSender()] = 0;\n if (pending != 0) {\n JOE.safeTransfer(_msgSender(), pending);\n emit Harvest(_msgSender(), _pid, pending);\n }\n }\n}\n" + }, + "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../GSN/ContextUpgradeable.sol\";\nimport \"../proxy/Initializable.sol\";\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __Ownable_init() internal initializer {\n __Context_init_unchained();\n __Ownable_init_unchained();\n }\n\n function __Ownable_init_unchained() internal initializer {\n address msgSender = _msgSender();\n _owner = msgSender;\n emit OwnershipTransferred(address(0), msgSender);\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(_owner == _msgSender(), \"Ownable: caller is not the owner\");\n _;\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n emit OwnershipTransferred(_owner, address(0));\n _owner = address(0);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n emit OwnershipTransferred(_owner, newOwner);\n _owner = newOwner;\n }\n uint256[49] private __gap;\n}\n" + }, + "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMathUpgradeable {\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n *\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n return sub(a, b, \"SafeMath: subtraction overflow\");\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b <= a, errorMessage);\n uint256 c = a - b;\n\n return c;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n *\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n return div(a, b, \"SafeMath: division by zero\");\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b > 0, errorMessage);\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n return c;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n return mod(a, b, \"SafeMath: modulo by zero\");\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * Reverts with custom message when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b != 0, errorMessage);\n return a % b;\n }\n}\n" + }, + "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// solhint-disable-next-line compiler-version\npragma solidity >=0.4.24 <0.8.0;\n\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n * \n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}.\n * \n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n */\nabstract contract Initializable {\n\n /**\n * @dev Indicates that the contract has been initialized.\n */\n bool private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Modifier to protect an initializer function from being invoked twice.\n */\n modifier initializer() {\n require(_initializing || _isConstructor() || !_initialized, \"Initializable: contract is already initialized\");\n\n bool isTopLevelCall = !_initializing;\n if (isTopLevelCall) {\n _initializing = true;\n _initialized = true;\n }\n\n _;\n\n if (isTopLevelCall) {\n _initializing = false;\n }\n }\n\n /// @dev Returns true if and only if the function is running in the constructor\n function _isConstructor() private view returns (bool) {\n // extcodesize checks the size of the code stored in an address, and\n // address returns the current address. Since the code is still not\n // deployed when running a constructor, any checks on its code size will\n // yield zero, making it an effective way to detect if a contract is\n // under construction or not.\n address self = address(this);\n uint256 cs;\n // solhint-disable-next-line no-inline-assembly\n assembly { cs := extcodesize(self) }\n return cs == 0;\n }\n}\n" + }, + "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\nimport \"../proxy/Initializable.sol\";\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuardUpgradeable is Initializable {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n function __ReentrancyGuard_init() internal initializer {\n __ReentrancyGuard_init_unchained();\n }\n\n function __ReentrancyGuard_init_unchained() internal initializer {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and make it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n uint256[49] private __gap;\n}\n" + }, + "contracts/interfaces/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\ninterface IERC20 {\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 amount) external returns (bool);\n\n event Transfer(address indexed from, address indexed to, uint256 value);\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n // EIP 2612\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n}\n" + }, + "contracts/interfaces/IMasterChefJoe.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\nimport \"../libraries/BoringJoeERC20.sol\";\n\ninterface IMasterChefJoe {\n using BoringJoeERC20 for IERC20;\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\n }\n\n function userInfo(uint256 _pid, address _user) external view returns (IMasterChefJoe.UserInfo memory);\n\n function poolInfo(uint256 pid) external view returns (IMasterChefJoe.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function joePerSec() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n\n function devPercent() external view returns (uint256);\n\n function treasuryPercent() external view returns (uint256);\n\n function investorPercent() external view returns (uint256);\n}\n" + }, + "contracts/interfaces/IRewarder.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\nimport \"./IERC20.sol\";\n\ninterface IRewarder {\n function onJoeReward(address user, uint256 newLpAmount) external;\n\n function pendingTokens(address user) external view returns (uint256 pending);\n\n function rewardToken() external view returns (IERC20);\n}\n" + }, + "contracts/libraries/BoringJoeERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\nimport \"../interfaces/IERC20.sol\";\n\n// solhint-disable avoid-low-level-calls\n\nlibrary BoringJoeERC20 {\n bytes4 private constant SIG_SYMBOL = 0x95d89b41; // symbol()\n bytes4 private constant SIG_NAME = 0x06fdde03; // name()\n bytes4 private constant SIG_DECIMALS = 0x313ce567; // decimals()\n bytes4 private constant SIG_TRANSFER = 0xa9059cbb; // transfer(address,uint256)\n bytes4 private constant SIG_TRANSFER_FROM = 0x23b872dd; // transferFrom(address,address,uint256)\n\n function returnDataToString(bytes memory data) internal pure returns (string memory) {\n if (data.length >= 64) {\n return abi.decode(data, (string));\n } else if (data.length == 32) {\n uint8 i = 0;\n while (i < 32 && data[i] != 0) {\n i++;\n }\n bytes memory bytesArray = new bytes(i);\n for (i = 0; i < 32 && data[i] != 0; i++) {\n bytesArray[i] = data[i];\n }\n return string(bytesArray);\n } else {\n return \"???\";\n }\n }\n\n /// @notice Provides a safe ERC20.symbol version which returns '???' as fallback string.\n /// @param token The address of the ERC-20 token contract.\n /// @return (string) Token symbol.\n function safeSymbol(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_SYMBOL));\n return success ? returnDataToString(data) : \"???\";\n }\n\n /// @notice Provides a safe ERC20.name version which returns '???' as fallback string.\n /// @param token The address of the ERC-20 token contract.\n /// @return (string) Token name.\n function safeName(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_NAME));\n return success ? returnDataToString(data) : \"???\";\n }\n\n /// @notice Provides a safe ERC20.decimals version which returns '18' as fallback value.\n /// @param token The address of the ERC-20 token contract.\n /// @return (uint8) Token decimals.\n function safeDecimals(IERC20 token) internal view returns (uint8) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_DECIMALS));\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\n }\n\n /// @notice Provides a safe ERC20.transfer version for different ERC-20 implementations.\n /// Reverts on a failed transfer.\n /// @param token The address of the ERC-20 token.\n /// @param to Transfer tokens to.\n /// @param amount The token amount.\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(SIG_TRANSFER, to, amount));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"BoringERC20: Transfer failed\");\n }\n\n /// @notice Provides a safe ERC20.transferFrom version for different ERC-20 implementations.\n /// Reverts on a failed transfer.\n /// @param token The address of the ERC-20 token.\n /// @param from Transfer tokens from.\n /// @param to Transfer tokens to.\n /// @param amount The token amount.\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(\n abi.encodeWithSelector(SIG_TRANSFER_FROM, from, to, amount)\n );\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"BoringERC20: TransferFrom failed\");\n }\n}\n" + }, + "contracts/traderjoe/libraries/Math.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\n// a library for performing various math operations\n\nlibrary Math {\n function min(uint256 x, uint256 y) internal pure returns (uint256 z) {\n z = x < y ? x : y;\n }\n\n // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)\n function sqrt(uint256 y) internal pure returns (uint256 z) {\n if (y > 3) {\n z = y;\n uint256 x = y / 2 + 1;\n while (x < z) {\n z = x;\n x = (y / x + x) / 2;\n }\n } else if (y != 0) {\n z = 1;\n }\n }\n}\n" + }, + "@openzeppelin/contracts-upgradeable/GSN/ContextUpgradeable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\nimport \"../proxy/Initializable.sol\";\n\n/*\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with GSN meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n function __Context_init() internal initializer {\n __Context_init_unchained();\n }\n\n function __Context_init_unchained() internal initializer {\n }\n function _msgSender() internal view virtual returns (address payable) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes memory) {\n this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n return msg.data;\n }\n uint256[50] private __gap;\n}\n" + }, + "contracts/traderjoe/JoePair.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\nimport \"./JoeERC20.sol\";\nimport \"./libraries/Math.sol\";\nimport \"./libraries/UQ112x112.sol\";\nimport \"./interfaces/IERC20.sol\";\nimport \"./interfaces/IJoeFactory.sol\";\nimport \"./interfaces/IJoeCallee.sol\";\n\ninterface IMigrator {\n // Return the desired amount of liquidity token that the migrator wants.\n function desiredLiquidity() external view returns (uint256);\n}\n\ncontract JoePair is JoeERC20 {\n using SafeMathJoe for uint256;\n using UQ112x112 for uint224;\n\n uint256 public constant MINIMUM_LIQUIDITY = 10**3;\n bytes4 private constant SELECTOR = bytes4(keccak256(bytes(\"transfer(address,uint256)\")));\n\n address public factory;\n address public token0;\n address public token1;\n\n uint112 private reserve0; // uses single storage slot, accessible via getReserves\n uint112 private reserve1; // uses single storage slot, accessible via getReserves\n uint32 private blockTimestampLast; // uses single storage slot, accessible via getReserves\n\n uint256 public price0CumulativeLast;\n uint256 public price1CumulativeLast;\n uint256 public kLast; // reserve0 * reserve1, as of immediately after the most recent liquidity event\n\n uint256 private unlocked = 1;\n modifier lock() {\n require(unlocked == 1, \"Joe: LOCKED\");\n unlocked = 0;\n _;\n unlocked = 1;\n }\n\n function getReserves()\n public\n view\n returns (\n uint112 _reserve0,\n uint112 _reserve1,\n uint32 _blockTimestampLast\n )\n {\n _reserve0 = reserve0;\n _reserve1 = reserve1;\n _blockTimestampLast = blockTimestampLast;\n }\n\n function _safeTransfer(\n address token,\n address to,\n uint256 value\n ) private {\n (bool success, bytes memory data) = token.call(abi.encodeWithSelector(SELECTOR, to, value));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"Joe: TRANSFER_FAILED\");\n }\n\n event Mint(address indexed sender, uint256 amount0, uint256 amount1);\n event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);\n event Swap(\n address indexed sender,\n uint256 amount0In,\n uint256 amount1In,\n uint256 amount0Out,\n uint256 amount1Out,\n address indexed to\n );\n event Sync(uint112 reserve0, uint112 reserve1);\n\n constructor() public {\n factory = msg.sender;\n }\n\n // called once by the factory at time of deployment\n function initialize(address _token0, address _token1) external {\n require(msg.sender == factory, \"Joe: FORBIDDEN\"); // sufficient check\n token0 = _token0;\n token1 = _token1;\n }\n\n // update reserves and, on the first call per block, price accumulators\n function _update(\n uint256 balance0,\n uint256 balance1,\n uint112 _reserve0,\n uint112 _reserve1\n ) private {\n require(balance0 <= uint112(-1) && balance1 <= uint112(-1), \"Joe: OVERFLOW\");\n uint32 blockTimestamp = uint32(block.timestamp % 2**32);\n uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired\n if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) {\n // * never overflows, and + overflow is desired\n price0CumulativeLast += uint256(UQ112x112.encode(_reserve1).uqdiv(_reserve0)) * timeElapsed;\n price1CumulativeLast += uint256(UQ112x112.encode(_reserve0).uqdiv(_reserve1)) * timeElapsed;\n }\n reserve0 = uint112(balance0);\n reserve1 = uint112(balance1);\n blockTimestampLast = blockTimestamp;\n emit Sync(reserve0, reserve1);\n }\n\n // if fee is on, mint liquidity equivalent to 1/6th of the growth in sqrt(k)\n function _mintFee(uint112 _reserve0, uint112 _reserve1) private returns (bool feeOn) {\n address feeTo = IJoeFactory(factory).feeTo();\n feeOn = feeTo != address(0);\n uint256 _kLast = kLast; // gas savings\n if (feeOn) {\n if (_kLast != 0) {\n uint256 rootK = Math.sqrt(uint256(_reserve0).mul(_reserve1));\n uint256 rootKLast = Math.sqrt(_kLast);\n if (rootK > rootKLast) {\n uint256 numerator = totalSupply.mul(rootK.sub(rootKLast));\n uint256 denominator = rootK.mul(5).add(rootKLast);\n uint256 liquidity = numerator / denominator;\n if (liquidity > 0) _mint(feeTo, liquidity);\n }\n }\n } else if (_kLast != 0) {\n kLast = 0;\n }\n }\n\n // this low-level function should be called from a contract which performs important safety checks\n function mint(address to) external lock returns (uint256 liquidity) {\n (uint112 _reserve0, uint112 _reserve1, ) = getReserves(); // gas savings\n uint256 balance0 = IERC20Joe(token0).balanceOf(address(this));\n uint256 balance1 = IERC20Joe(token1).balanceOf(address(this));\n uint256 amount0 = balance0.sub(_reserve0);\n uint256 amount1 = balance1.sub(_reserve1);\n\n bool feeOn = _mintFee(_reserve0, _reserve1);\n uint256 _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee\n if (_totalSupply == 0) {\n address migrator = IJoeFactory(factory).migrator();\n if (msg.sender == migrator) {\n liquidity = IMigrator(migrator).desiredLiquidity();\n require(liquidity > 0 && liquidity != uint256(-1), \"Bad desired liquidity\");\n } else {\n require(migrator == address(0), \"Must not have migrator\");\n liquidity = Math.sqrt(amount0.mul(amount1)).sub(MINIMUM_LIQUIDITY);\n _mint(address(0), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens\n }\n } else {\n liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1);\n }\n require(liquidity > 0, \"Joe: INSUFFICIENT_LIQUIDITY_MINTED\");\n _mint(to, liquidity);\n\n _update(balance0, balance1, _reserve0, _reserve1);\n if (feeOn) kLast = uint256(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date\n emit Mint(msg.sender, amount0, amount1);\n }\n\n // this low-level function should be called from a contract which performs important safety checks\n function burn(address to) external lock returns (uint256 amount0, uint256 amount1) {\n (uint112 _reserve0, uint112 _reserve1, ) = getReserves(); // gas savings\n address _token0 = token0; // gas savings\n address _token1 = token1; // gas savings\n uint256 balance0 = IERC20Joe(_token0).balanceOf(address(this));\n uint256 balance1 = IERC20Joe(_token1).balanceOf(address(this));\n uint256 liquidity = balanceOf[address(this)];\n\n bool feeOn = _mintFee(_reserve0, _reserve1);\n uint256 _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee\n amount0 = liquidity.mul(balance0) / _totalSupply; // using balances ensures pro-rata distribution\n amount1 = liquidity.mul(balance1) / _totalSupply; // using balances ensures pro-rata distribution\n require(amount0 > 0 && amount1 > 0, \"Joe: INSUFFICIENT_LIQUIDITY_BURNED\");\n _burn(address(this), liquidity);\n _safeTransfer(_token0, to, amount0);\n _safeTransfer(_token1, to, amount1);\n balance0 = IERC20Joe(_token0).balanceOf(address(this));\n balance1 = IERC20Joe(_token1).balanceOf(address(this));\n\n _update(balance0, balance1, _reserve0, _reserve1);\n if (feeOn) kLast = uint256(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date\n emit Burn(msg.sender, amount0, amount1, to);\n }\n\n // this low-level function should be called from a contract which performs important safety checks\n function swap(\n uint256 amount0Out,\n uint256 amount1Out,\n address to,\n bytes calldata data\n ) external lock {\n require(amount0Out > 0 || amount1Out > 0, \"Joe: INSUFFICIENT_OUTPUT_AMOUNT\");\n (uint112 _reserve0, uint112 _reserve1, ) = getReserves(); // gas savings\n require(amount0Out < _reserve0 && amount1Out < _reserve1, \"Joe: INSUFFICIENT_LIQUIDITY\");\n\n uint256 balance0;\n uint256 balance1;\n {\n // scope for _token{0,1}, avoids stack too deep errors\n address _token0 = token0;\n address _token1 = token1;\n require(to != _token0 && to != _token1, \"Joe: INVALID_TO\");\n if (amount0Out > 0) _safeTransfer(_token0, to, amount0Out); // optimistically transfer tokens\n if (amount1Out > 0) _safeTransfer(_token1, to, amount1Out); // optimistically transfer tokens\n if (data.length > 0) IJoeCallee(to).joeCall(msg.sender, amount0Out, amount1Out, data);\n balance0 = IERC20Joe(_token0).balanceOf(address(this));\n balance1 = IERC20Joe(_token1).balanceOf(address(this));\n }\n uint256 amount0In = balance0 > _reserve0 - amount0Out ? balance0 - (_reserve0 - amount0Out) : 0;\n uint256 amount1In = balance1 > _reserve1 - amount1Out ? balance1 - (_reserve1 - amount1Out) : 0;\n require(amount0In > 0 || amount1In > 0, \"Joe: INSUFFICIENT_INPUT_AMOUNT\");\n {\n // scope for reserve{0,1}Adjusted, avoids stack too deep errors\n uint256 balance0Adjusted = balance0.mul(1000).sub(amount0In.mul(3));\n uint256 balance1Adjusted = balance1.mul(1000).sub(amount1In.mul(3));\n require(balance0Adjusted.mul(balance1Adjusted) >= uint256(_reserve0).mul(_reserve1).mul(1000**2), \"Joe: K\");\n }\n\n _update(balance0, balance1, _reserve0, _reserve1);\n emit Swap(msg.sender, amount0In, amount1In, amount0Out, amount1Out, to);\n }\n\n // force balances to match reserves\n function skim(address to) external lock {\n address _token0 = token0; // gas savings\n address _token1 = token1; // gas savings\n _safeTransfer(_token0, to, IERC20Joe(_token0).balanceOf(address(this)).sub(reserve0));\n _safeTransfer(_token1, to, IERC20Joe(_token1).balanceOf(address(this)).sub(reserve1));\n }\n\n // force reserves to match balances\n function sync() external lock {\n _update(\n IERC20Joe(token0).balanceOf(address(this)),\n IERC20Joe(token1).balanceOf(address(this)),\n reserve0,\n reserve1\n );\n }\n}\n" + }, + "contracts/traderjoe/JoeERC20.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\nimport \"./libraries/SafeMath.sol\";\n\ncontract JoeERC20 {\n using SafeMathJoe for uint256;\n\n string public constant name = \"Joe LP Token\";\n string public constant symbol = \"JLP\";\n uint8 public constant decimals = 18;\n uint256 public totalSupply;\n mapping(address => uint256) public balanceOf;\n mapping(address => mapping(address => uint256)) public allowance;\n\n bytes32 public DOMAIN_SEPARATOR;\n // keccak256(\"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)\");\n bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;\n mapping(address => uint256) public nonces;\n\n event Approval(address indexed owner, address indexed spender, uint256 value);\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n constructor() public {\n uint256 chainId;\n assembly {\n chainId := chainid()\n }\n DOMAIN_SEPARATOR = keccak256(\n abi.encode(\n keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\"),\n keccak256(bytes(name)),\n keccak256(bytes(\"1\")),\n chainId,\n address(this)\n )\n );\n }\n\n function _mint(address to, uint256 value) internal {\n totalSupply = totalSupply.add(value);\n balanceOf[to] = balanceOf[to].add(value);\n emit Transfer(address(0), to, value);\n }\n\n function _burn(address from, uint256 value) internal {\n balanceOf[from] = balanceOf[from].sub(value);\n totalSupply = totalSupply.sub(value);\n emit Transfer(from, address(0), value);\n }\n\n function _approve(\n address owner,\n address spender,\n uint256 value\n ) private {\n allowance[owner][spender] = value;\n emit Approval(owner, spender, value);\n }\n\n function _transfer(\n address from,\n address to,\n uint256 value\n ) private {\n balanceOf[from] = balanceOf[from].sub(value);\n balanceOf[to] = balanceOf[to].add(value);\n emit Transfer(from, to, value);\n }\n\n function approve(address spender, uint256 value) external returns (bool) {\n _approve(msg.sender, spender, value);\n return true;\n }\n\n function transfer(address to, uint256 value) external returns (bool) {\n _transfer(msg.sender, to, value);\n return true;\n }\n\n function transferFrom(\n address from,\n address to,\n uint256 value\n ) external returns (bool) {\n if (allowance[from][msg.sender] != uint256(-1)) {\n allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);\n }\n _transfer(from, to, value);\n return true;\n }\n\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external {\n require(deadline >= block.timestamp, \"Joe: EXPIRED\");\n bytes32 digest = keccak256(\n abi.encodePacked(\n \"\\x19\\x01\",\n DOMAIN_SEPARATOR,\n keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))\n )\n );\n address recoveredAddress = ecrecover(digest, v, r, s);\n require(recoveredAddress != address(0) && recoveredAddress == owner, \"Joe: INVALID_SIGNATURE\");\n _approve(owner, spender, value);\n }\n}\n" + }, + "contracts/traderjoe/libraries/UQ112x112.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\n// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))\n\n// range: [0, 2**112 - 1]\n// resolution: 1 / 2**112\n\nlibrary UQ112x112 {\n uint224 constant Q112 = 2**112;\n\n // encode a uint112 as a UQ112x112\n function encode(uint112 y) internal pure returns (uint224 z) {\n z = uint224(y) * Q112; // never overflows\n }\n\n // divide a UQ112x112 by a uint112, returning a UQ112x112\n function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) {\n z = x / uint224(y);\n }\n}\n" + }, + "contracts/traderjoe/interfaces/IERC20.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\ninterface IERC20Joe {\n event Approval(address indexed owner, address indexed spender, uint256 value);\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n function name() external view returns (string memory);\n\n function symbol() external view returns (string memory);\n\n function decimals() external view returns (uint8);\n\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address owner) external view returns (uint256);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 value) external returns (bool);\n\n function transfer(address to, uint256 value) external returns (bool);\n\n function transferFrom(\n address from,\n address to,\n uint256 value\n ) external returns (bool);\n}\n" + }, + "contracts/traderjoe/interfaces/IJoeFactory.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\ninterface IJoeFactory {\n event PairCreated(address indexed token0, address indexed token1, address pair, uint256);\n\n function feeTo() external view returns (address);\n\n function feeToSetter() external view returns (address);\n\n function migrator() external view returns (address);\n\n function getPair(address tokenA, address tokenB) external view returns (address pair);\n\n function allPairs(uint256) external view returns (address pair);\n\n function allPairsLength() external view returns (uint256);\n\n function createPair(address tokenA, address tokenB) external returns (address pair);\n\n function setFeeTo(address) external;\n\n function setFeeToSetter(address) external;\n\n function setMigrator(address) external;\n}\n" + }, + "contracts/traderjoe/interfaces/IJoeCallee.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\ninterface IJoeCallee {\n function joeCall(\n address sender,\n uint256 amount0,\n uint256 amount1,\n bytes calldata data\n ) external;\n}\n" + }, + "contracts/traderjoe/libraries/SafeMath.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\n// a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)\n\nlibrary SafeMathJoe {\n function add(uint256 x, uint256 y) internal pure returns (uint256 z) {\n require((z = x + y) >= x, \"ds-math-add-overflow\");\n }\n\n function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {\n require((z = x - y) <= x, \"ds-math-sub-underflow\");\n }\n\n function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {\n require(y == 0 || (z = x * y) / y == x, \"ds-math-mul-overflow\");\n }\n}\n" + }, + "contracts/traderjoe/JoeRouter02.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\nimport \"./libraries/JoeLibrary.sol\";\nimport \"./libraries/SafeMath.sol\";\nimport \"./libraries/TransferHelper.sol\";\nimport \"./interfaces/IJoeRouter02.sol\";\nimport \"./interfaces/IJoeFactory.sol\";\nimport \"./interfaces/IERC20.sol\";\nimport \"./interfaces/IWAVAX.sol\";\n\ncontract JoeRouter02 is IJoeRouter02 {\n using SafeMathJoe for uint256;\n\n address public immutable override factory;\n address public immutable override WAVAX;\n\n modifier ensure(uint256 deadline) {\n require(deadline >= block.timestamp, \"JoeRouter: EXPIRED\");\n _;\n }\n\n constructor(address _factory, address _WAVAX) public {\n factory = _factory;\n WAVAX = _WAVAX;\n }\n\n receive() external payable {\n assert(msg.sender == WAVAX); // only accept AVAX via fallback from the WAVAX contract\n }\n\n // **** ADD LIQUIDITY ****\n function _addLiquidity(\n address tokenA,\n address tokenB,\n uint256 amountADesired,\n uint256 amountBDesired,\n uint256 amountAMin,\n uint256 amountBMin\n ) internal virtual returns (uint256 amountA, uint256 amountB) {\n // create the pair if it doesn't exist yet\n if (IJoeFactory(factory).getPair(tokenA, tokenB) == address(0)) {\n IJoeFactory(factory).createPair(tokenA, tokenB);\n }\n (uint256 reserveA, uint256 reserveB) = JoeLibrary.getReserves(factory, tokenA, tokenB);\n if (reserveA == 0 && reserveB == 0) {\n (amountA, amountB) = (amountADesired, amountBDesired);\n } else {\n uint256 amountBOptimal = JoeLibrary.quote(amountADesired, reserveA, reserveB);\n if (amountBOptimal <= amountBDesired) {\n require(amountBOptimal >= amountBMin, \"JoeRouter: INSUFFICIENT_B_AMOUNT\");\n (amountA, amountB) = (amountADesired, amountBOptimal);\n } else {\n uint256 amountAOptimal = JoeLibrary.quote(amountBDesired, reserveB, reserveA);\n assert(amountAOptimal <= amountADesired);\n require(amountAOptimal >= amountAMin, \"JoeRouter: INSUFFICIENT_A_AMOUNT\");\n (amountA, amountB) = (amountAOptimal, amountBDesired);\n }\n }\n }\n\n function addLiquidity(\n address tokenA,\n address tokenB,\n uint256 amountADesired,\n uint256 amountBDesired,\n uint256 amountAMin,\n uint256 amountBMin,\n address to,\n uint256 deadline\n )\n external\n virtual\n override\n ensure(deadline)\n returns (\n uint256 amountA,\n uint256 amountB,\n uint256 liquidity\n )\n {\n (amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin);\n address pair = JoeLibrary.pairFor(factory, tokenA, tokenB);\n TransferHelper.safeTransferFrom(tokenA, msg.sender, pair, amountA);\n TransferHelper.safeTransferFrom(tokenB, msg.sender, pair, amountB);\n liquidity = IJoePair(pair).mint(to);\n }\n\n function addLiquidityAVAX(\n address token,\n uint256 amountTokenDesired,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline\n )\n external\n payable\n virtual\n override\n ensure(deadline)\n returns (\n uint256 amountToken,\n uint256 amountAVAX,\n uint256 liquidity\n )\n {\n (amountToken, amountAVAX) = _addLiquidity(\n token,\n WAVAX,\n amountTokenDesired,\n msg.value,\n amountTokenMin,\n amountAVAXMin\n );\n address pair = JoeLibrary.pairFor(factory, token, WAVAX);\n TransferHelper.safeTransferFrom(token, msg.sender, pair, amountToken);\n IWAVAX(WAVAX).deposit{value: amountAVAX}();\n assert(IWAVAX(WAVAX).transfer(pair, amountAVAX));\n liquidity = IJoePair(pair).mint(to);\n // refund dust eth, if any\n if (msg.value > amountAVAX) TransferHelper.safeTransferAVAX(msg.sender, msg.value - amountAVAX);\n }\n\n // **** REMOVE LIQUIDITY ****\n function removeLiquidity(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n address to,\n uint256 deadline\n ) public virtual override ensure(deadline) returns (uint256 amountA, uint256 amountB) {\n address pair = JoeLibrary.pairFor(factory, tokenA, tokenB);\n IJoePair(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair\n (uint256 amount0, uint256 amount1) = IJoePair(pair).burn(to);\n (address token0, ) = JoeLibrary.sortTokens(tokenA, tokenB);\n (amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0);\n require(amountA >= amountAMin, \"JoeRouter: INSUFFICIENT_A_AMOUNT\");\n require(amountB >= amountBMin, \"JoeRouter: INSUFFICIENT_B_AMOUNT\");\n }\n\n function removeLiquidityAVAX(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline\n ) public virtual override ensure(deadline) returns (uint256 amountToken, uint256 amountAVAX) {\n (amountToken, amountAVAX) = removeLiquidity(\n token,\n WAVAX,\n liquidity,\n amountTokenMin,\n amountAVAXMin,\n address(this),\n deadline\n );\n TransferHelper.safeTransfer(token, to, amountToken);\n IWAVAX(WAVAX).withdraw(amountAVAX);\n TransferHelper.safeTransferAVAX(to, amountAVAX);\n }\n\n function removeLiquidityWithPermit(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n address to,\n uint256 deadline,\n bool approveMax,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external virtual override returns (uint256 amountA, uint256 amountB) {\n address pair = JoeLibrary.pairFor(factory, tokenA, tokenB);\n uint256 value = approveMax ? uint256(-1) : liquidity;\n IJoePair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);\n (amountA, amountB) = removeLiquidity(tokenA, tokenB, liquidity, amountAMin, amountBMin, to, deadline);\n }\n\n function removeLiquidityAVAXWithPermit(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline,\n bool approveMax,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external virtual override returns (uint256 amountToken, uint256 amountAVAX) {\n address pair = JoeLibrary.pairFor(factory, token, WAVAX);\n uint256 value = approveMax ? uint256(-1) : liquidity;\n IJoePair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);\n (amountToken, amountAVAX) = removeLiquidityAVAX(token, liquidity, amountTokenMin, amountAVAXMin, to, deadline);\n }\n\n // **** REMOVE LIQUIDITY (supporting fee-on-transfer tokens) ****\n function removeLiquidityAVAXSupportingFeeOnTransferTokens(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline\n ) public virtual override ensure(deadline) returns (uint256 amountAVAX) {\n (, amountAVAX) = removeLiquidity(\n token,\n WAVAX,\n liquidity,\n amountTokenMin,\n amountAVAXMin,\n address(this),\n deadline\n );\n TransferHelper.safeTransfer(token, to, IERC20Joe(token).balanceOf(address(this)));\n IWAVAX(WAVAX).withdraw(amountAVAX);\n TransferHelper.safeTransferAVAX(to, amountAVAX);\n }\n\n function removeLiquidityAVAXWithPermitSupportingFeeOnTransferTokens(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline,\n bool approveMax,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external virtual override returns (uint256 amountAVAX) {\n address pair = JoeLibrary.pairFor(factory, token, WAVAX);\n uint256 value = approveMax ? uint256(-1) : liquidity;\n IJoePair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);\n amountAVAX = removeLiquidityAVAXSupportingFeeOnTransferTokens(\n token,\n liquidity,\n amountTokenMin,\n amountAVAXMin,\n to,\n deadline\n );\n }\n\n // **** SWAP ****\n // requires the initial amount to have already been sent to the first pair\n function _swap(\n uint256[] memory amounts,\n address[] memory path,\n address _to\n ) internal virtual {\n for (uint256 i; i < path.length - 1; i++) {\n (address input, address output) = (path[i], path[i + 1]);\n (address token0, ) = JoeLibrary.sortTokens(input, output);\n uint256 amountOut = amounts[i + 1];\n (uint256 amount0Out, uint256 amount1Out) = input == token0\n ? (uint256(0), amountOut)\n : (amountOut, uint256(0));\n address to = i < path.length - 2 ? JoeLibrary.pairFor(factory, output, path[i + 2]) : _to;\n IJoePair(JoeLibrary.pairFor(factory, input, output)).swap(amount0Out, amount1Out, to, new bytes(0));\n }\n }\n\n function swapExactTokensForTokens(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external virtual override ensure(deadline) returns (uint256[] memory amounts) {\n amounts = JoeLibrary.getAmountsOut(factory, amountIn, path);\n require(amounts[amounts.length - 1] >= amountOutMin, \"JoeRouter: INSUFFICIENT_OUTPUT_AMOUNT\");\n TransferHelper.safeTransferFrom(path[0], msg.sender, JoeLibrary.pairFor(factory, path[0], path[1]), amounts[0]);\n _swap(amounts, path, to);\n }\n\n function swapTokensForExactTokens(\n uint256 amountOut,\n uint256 amountInMax,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external virtual override ensure(deadline) returns (uint256[] memory amounts) {\n amounts = JoeLibrary.getAmountsIn(factory, amountOut, path);\n require(amounts[0] <= amountInMax, \"JoeRouter: EXCESSIVE_INPUT_AMOUNT\");\n TransferHelper.safeTransferFrom(path[0], msg.sender, JoeLibrary.pairFor(factory, path[0], path[1]), amounts[0]);\n _swap(amounts, path, to);\n }\n\n function swapExactAVAXForTokens(\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external payable virtual override ensure(deadline) returns (uint256[] memory amounts) {\n require(path[0] == WAVAX, \"JoeRouter: INVALID_PATH\");\n amounts = JoeLibrary.getAmountsOut(factory, msg.value, path);\n require(amounts[amounts.length - 1] >= amountOutMin, \"JoeRouter: INSUFFICIENT_OUTPUT_AMOUNT\");\n IWAVAX(WAVAX).deposit{value: amounts[0]}();\n assert(IWAVAX(WAVAX).transfer(JoeLibrary.pairFor(factory, path[0], path[1]), amounts[0]));\n _swap(amounts, path, to);\n }\n\n function swapTokensForExactAVAX(\n uint256 amountOut,\n uint256 amountInMax,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external virtual override ensure(deadline) returns (uint256[] memory amounts) {\n require(path[path.length - 1] == WAVAX, \"JoeRouter: INVALID_PATH\");\n amounts = JoeLibrary.getAmountsIn(factory, amountOut, path);\n require(amounts[0] <= amountInMax, \"JoeRouter: EXCESSIVE_INPUT_AMOUNT\");\n TransferHelper.safeTransferFrom(path[0], msg.sender, JoeLibrary.pairFor(factory, path[0], path[1]), amounts[0]);\n _swap(amounts, path, address(this));\n IWAVAX(WAVAX).withdraw(amounts[amounts.length - 1]);\n TransferHelper.safeTransferAVAX(to, amounts[amounts.length - 1]);\n }\n\n function swapExactTokensForAVAX(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external virtual override ensure(deadline) returns (uint256[] memory amounts) {\n require(path[path.length - 1] == WAVAX, \"JoeRouter: INVALID_PATH\");\n amounts = JoeLibrary.getAmountsOut(factory, amountIn, path);\n require(amounts[amounts.length - 1] >= amountOutMin, \"JoeRouter: INSUFFICIENT_OUTPUT_AMOUNT\");\n TransferHelper.safeTransferFrom(path[0], msg.sender, JoeLibrary.pairFor(factory, path[0], path[1]), amounts[0]);\n _swap(amounts, path, address(this));\n IWAVAX(WAVAX).withdraw(amounts[amounts.length - 1]);\n TransferHelper.safeTransferAVAX(to, amounts[amounts.length - 1]);\n }\n\n function swapAVAXForExactTokens(\n uint256 amountOut,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external payable virtual override ensure(deadline) returns (uint256[] memory amounts) {\n require(path[0] == WAVAX, \"JoeRouter: INVALID_PATH\");\n amounts = JoeLibrary.getAmountsIn(factory, amountOut, path);\n require(amounts[0] <= msg.value, \"JoeRouter: EXCESSIVE_INPUT_AMOUNT\");\n IWAVAX(WAVAX).deposit{value: amounts[0]}();\n assert(IWAVAX(WAVAX).transfer(JoeLibrary.pairFor(factory, path[0], path[1]), amounts[0]));\n _swap(amounts, path, to);\n // refund dust eth, if any\n if (msg.value > amounts[0]) TransferHelper.safeTransferAVAX(msg.sender, msg.value - amounts[0]);\n }\n\n // **** SWAP (supporting fee-on-transfer tokens) ****\n // requires the initial amount to have already been sent to the first pair\n function _swapSupportingFeeOnTransferTokens(address[] memory path, address _to) internal virtual {\n for (uint256 i; i < path.length - 1; i++) {\n (address input, address output) = (path[i], path[i + 1]);\n (address token0, ) = JoeLibrary.sortTokens(input, output);\n IJoePair pair = IJoePair(JoeLibrary.pairFor(factory, input, output));\n uint256 amountInput;\n uint256 amountOutput;\n {\n // scope to avoid stack too deep errors\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n (uint256 reserveInput, uint256 reserveOutput) = input == token0\n ? (reserve0, reserve1)\n : (reserve1, reserve0);\n amountInput = IERC20Joe(input).balanceOf(address(pair)).sub(reserveInput);\n amountOutput = JoeLibrary.getAmountOut(amountInput, reserveInput, reserveOutput);\n }\n (uint256 amount0Out, uint256 amount1Out) = input == token0\n ? (uint256(0), amountOutput)\n : (amountOutput, uint256(0));\n address to = i < path.length - 2 ? JoeLibrary.pairFor(factory, output, path[i + 2]) : _to;\n pair.swap(amount0Out, amount1Out, to, new bytes(0));\n }\n }\n\n function swapExactTokensForTokensSupportingFeeOnTransferTokens(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external virtual override ensure(deadline) {\n TransferHelper.safeTransferFrom(path[0], msg.sender, JoeLibrary.pairFor(factory, path[0], path[1]), amountIn);\n uint256 balanceBefore = IERC20Joe(path[path.length - 1]).balanceOf(to);\n _swapSupportingFeeOnTransferTokens(path, to);\n require(\n IERC20Joe(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin,\n \"JoeRouter: INSUFFICIENT_OUTPUT_AMOUNT\"\n );\n }\n\n function swapExactAVAXForTokensSupportingFeeOnTransferTokens(\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external payable virtual override ensure(deadline) {\n require(path[0] == WAVAX, \"JoeRouter: INVALID_PATH\");\n uint256 amountIn = msg.value;\n IWAVAX(WAVAX).deposit{value: amountIn}();\n assert(IWAVAX(WAVAX).transfer(JoeLibrary.pairFor(factory, path[0], path[1]), amountIn));\n uint256 balanceBefore = IERC20Joe(path[path.length - 1]).balanceOf(to);\n _swapSupportingFeeOnTransferTokens(path, to);\n require(\n IERC20Joe(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin,\n \"JoeRouter: INSUFFICIENT_OUTPUT_AMOUNT\"\n );\n }\n\n function swapExactTokensForAVAXSupportingFeeOnTransferTokens(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external virtual override ensure(deadline) {\n require(path[path.length - 1] == WAVAX, \"JoeRouter: INVALID_PATH\");\n TransferHelper.safeTransferFrom(path[0], msg.sender, JoeLibrary.pairFor(factory, path[0], path[1]), amountIn);\n _swapSupportingFeeOnTransferTokens(path, address(this));\n uint256 amountOut = IERC20Joe(WAVAX).balanceOf(address(this));\n require(amountOut >= amountOutMin, \"JoeRouter: INSUFFICIENT_OUTPUT_AMOUNT\");\n IWAVAX(WAVAX).withdraw(amountOut);\n TransferHelper.safeTransferAVAX(to, amountOut);\n }\n\n // **** LIBRARY FUNCTIONS ****\n function quote(\n uint256 amountA,\n uint256 reserveA,\n uint256 reserveB\n ) public pure virtual override returns (uint256 amountB) {\n return JoeLibrary.quote(amountA, reserveA, reserveB);\n }\n\n function getAmountOut(\n uint256 amountIn,\n uint256 reserveIn,\n uint256 reserveOut\n ) public pure virtual override returns (uint256 amountOut) {\n return JoeLibrary.getAmountOut(amountIn, reserveIn, reserveOut);\n }\n\n function getAmountIn(\n uint256 amountOut,\n uint256 reserveIn,\n uint256 reserveOut\n ) public pure virtual override returns (uint256 amountIn) {\n return JoeLibrary.getAmountIn(amountOut, reserveIn, reserveOut);\n }\n\n function getAmountsOut(uint256 amountIn, address[] memory path)\n public\n view\n virtual\n override\n returns (uint256[] memory amounts)\n {\n return JoeLibrary.getAmountsOut(factory, amountIn, path);\n }\n\n function getAmountsIn(uint256 amountOut, address[] memory path)\n public\n view\n virtual\n override\n returns (uint256[] memory amounts)\n {\n return JoeLibrary.getAmountsIn(factory, amountOut, path);\n }\n}\n" + }, + "contracts/traderjoe/libraries/JoeLibrary.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\nimport \"../interfaces/IJoePair.sol\";\n\nimport \"./SafeMath.sol\";\n\nlibrary JoeLibrary {\n using SafeMathJoe for uint256;\n\n // returns sorted token addresses, used to handle return values from pairs sorted in this order\n function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {\n require(tokenA != tokenB, \"JoeLibrary: IDENTICAL_ADDRESSES\");\n (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);\n require(token0 != address(0), \"JoeLibrary: ZERO_ADDRESS\");\n }\n\n // calculates the CREATE2 address for a pair without making any external calls\n function pairFor(\n address factory,\n address tokenA,\n address tokenB\n ) internal pure returns (address pair) {\n (address token0, address token1) = sortTokens(tokenA, tokenB);\n pair = address(\n uint256(\n keccak256(\n abi.encodePacked(\n hex\"ff\",\n factory,\n keccak256(abi.encodePacked(token0, token1)),\n hex\"0bbca9af0511ad1a1da383135cf3a8d2ac620e549ef9f6ae3a4c33c2fed0af91\" // init code fuji\n )\n )\n )\n );\n }\n\n // fetches and sorts the reserves for a pair\n function getReserves(\n address factory,\n address tokenA,\n address tokenB\n ) internal view returns (uint256 reserveA, uint256 reserveB) {\n (address token0, ) = sortTokens(tokenA, tokenB);\n (uint256 reserve0, uint256 reserve1, ) = IJoePair(pairFor(factory, tokenA, tokenB)).getReserves();\n (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);\n }\n\n // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset\n function quote(\n uint256 amountA,\n uint256 reserveA,\n uint256 reserveB\n ) internal pure returns (uint256 amountB) {\n require(amountA > 0, \"JoeLibrary: INSUFFICIENT_AMOUNT\");\n require(reserveA > 0 && reserveB > 0, \"JoeLibrary: INSUFFICIENT_LIQUIDITY\");\n amountB = amountA.mul(reserveB) / reserveA;\n }\n\n // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset\n function getAmountOut(\n uint256 amountIn,\n uint256 reserveIn,\n uint256 reserveOut\n ) internal pure returns (uint256 amountOut) {\n require(amountIn > 0, \"JoeLibrary: INSUFFICIENT_INPUT_AMOUNT\");\n require(reserveIn > 0 && reserveOut > 0, \"JoeLibrary: INSUFFICIENT_LIQUIDITY\");\n uint256 amountInWithFee = amountIn.mul(997);\n uint256 numerator = amountInWithFee.mul(reserveOut);\n uint256 denominator = reserveIn.mul(1000).add(amountInWithFee);\n amountOut = numerator / denominator;\n }\n\n // given an output amount of an asset and pair reserves, returns a required input amount of the other asset\n function getAmountIn(\n uint256 amountOut,\n uint256 reserveIn,\n uint256 reserveOut\n ) internal pure returns (uint256 amountIn) {\n require(amountOut > 0, \"JoeLibrary: INSUFFICIENT_OUTPUT_AMOUNT\");\n require(reserveIn > 0 && reserveOut > 0, \"JoeLibrary: INSUFFICIENT_LIQUIDITY\");\n uint256 numerator = reserveIn.mul(amountOut).mul(1000);\n uint256 denominator = reserveOut.sub(amountOut).mul(997);\n amountIn = (numerator / denominator).add(1);\n }\n\n // performs chained getAmountOut calculations on any number of pairs\n function getAmountsOut(\n address factory,\n uint256 amountIn,\n address[] memory path\n ) internal view returns (uint256[] memory amounts) {\n require(path.length >= 2, \"JoeLibrary: INVALID_PATH\");\n amounts = new uint256[](path.length);\n amounts[0] = amountIn;\n for (uint256 i; i < path.length - 1; i++) {\n (uint256 reserveIn, uint256 reserveOut) = getReserves(factory, path[i], path[i + 1]);\n amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);\n }\n }\n\n // performs chained getAmountIn calculations on any number of pairs\n function getAmountsIn(\n address factory,\n uint256 amountOut,\n address[] memory path\n ) internal view returns (uint256[] memory amounts) {\n require(path.length >= 2, \"JoeLibrary: INVALID_PATH\");\n amounts = new uint256[](path.length);\n amounts[amounts.length - 1] = amountOut;\n for (uint256 i = path.length - 1; i > 0; i--) {\n (uint256 reserveIn, uint256 reserveOut) = getReserves(factory, path[i - 1], path[i]);\n amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);\n }\n }\n}\n" + }, + "contracts/traderjoe/libraries/TransferHelper.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.6.0;\n\n// helper methods for interacting with ERC20 tokens and sending AVAX that do not consistently return true/false\nlibrary TransferHelper {\n function safeApprove(\n address token,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('approve(address,uint256)')));\n (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"TransferHelper: APPROVE_FAILED\");\n }\n\n function safeTransfer(\n address token,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('transfer(address,uint256)')));\n (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"TransferHelper: TRANSFER_FAILED\");\n }\n\n function safeTransferFrom(\n address token,\n address from,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));\n (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"TransferHelper: TRANSFER_FROM_FAILED\");\n }\n\n function safeTransferAVAX(address to, uint256 value) internal {\n (bool success, ) = to.call{value: value}(new bytes(0));\n require(success, \"TransferHelper: AVAX_TRANSFER_FAILED\");\n }\n}\n" + }, + "contracts/traderjoe/interfaces/IJoeRouter02.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.6.2;\n\nimport \"./IJoeRouter01.sol\";\n\ninterface IJoeRouter02 is IJoeRouter01 {\n function removeLiquidityAVAXSupportingFeeOnTransferTokens(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline\n ) external returns (uint256 amountAVAX);\n\n function removeLiquidityAVAXWithPermitSupportingFeeOnTransferTokens(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline,\n bool approveMax,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external returns (uint256 amountAVAX);\n\n function swapExactTokensForTokensSupportingFeeOnTransferTokens(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external;\n\n function swapExactAVAXForTokensSupportingFeeOnTransferTokens(\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external payable;\n\n function swapExactTokensForAVAXSupportingFeeOnTransferTokens(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external;\n}\n" + }, + "contracts/traderjoe/interfaces/IWAVAX.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\ninterface IWAVAX {\n function deposit() external payable;\n\n function transfer(address to, uint256 value) external returns (bool);\n\n function withdraw(uint256) external;\n}\n" + }, + "contracts/traderjoe/interfaces/IJoePair.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\ninterface IJoePair {\n event Approval(address indexed owner, address indexed spender, uint256 value);\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n function name() external pure returns (string memory);\n\n function symbol() external pure returns (string memory);\n\n function decimals() external pure returns (uint8);\n\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address owner) external view returns (uint256);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 value) external returns (bool);\n\n function transfer(address to, uint256 value) external returns (bool);\n\n function transferFrom(\n address from,\n address to,\n uint256 value\n ) external returns (bool);\n\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n\n function PERMIT_TYPEHASH() external pure returns (bytes32);\n\n function nonces(address owner) external view returns (uint256);\n\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n\n event Mint(address indexed sender, uint256 amount0, uint256 amount1);\n event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);\n event Swap(\n address indexed sender,\n uint256 amount0In,\n uint256 amount1In,\n uint256 amount0Out,\n uint256 amount1Out,\n address indexed to\n );\n event Sync(uint112 reserve0, uint112 reserve1);\n\n function MINIMUM_LIQUIDITY() external pure returns (uint256);\n\n function factory() external view returns (address);\n\n function token0() external view returns (address);\n\n function token1() external view returns (address);\n\n function getReserves()\n external\n view\n returns (\n uint112 reserve0,\n uint112 reserve1,\n uint32 blockTimestampLast\n );\n\n function price0CumulativeLast() external view returns (uint256);\n\n function price1CumulativeLast() external view returns (uint256);\n\n function kLast() external view returns (uint256);\n\n function mint(address to) external returns (uint256 liquidity);\n\n function burn(address to) external returns (uint256 amount0, uint256 amount1);\n\n function swap(\n uint256 amount0Out,\n uint256 amount1Out,\n address to,\n bytes calldata data\n ) external;\n\n function skim(address to) external;\n\n function sync() external;\n\n function initialize(address, address) external;\n}\n" + }, + "contracts/traderjoe/interfaces/IJoeRouter01.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.6.2;\n\ninterface IJoeRouter01 {\n function factory() external pure returns (address);\n\n function WAVAX() external pure returns (address);\n\n function addLiquidity(\n address tokenA,\n address tokenB,\n uint256 amountADesired,\n uint256 amountBDesired,\n uint256 amountAMin,\n uint256 amountBMin,\n address to,\n uint256 deadline\n )\n external\n returns (\n uint256 amountA,\n uint256 amountB,\n uint256 liquidity\n );\n\n function addLiquidityAVAX(\n address token,\n uint256 amountTokenDesired,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline\n )\n external\n payable\n returns (\n uint256 amountToken,\n uint256 amountAVAX,\n uint256 liquidity\n );\n\n function removeLiquidity(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n address to,\n uint256 deadline\n ) external returns (uint256 amountA, uint256 amountB);\n\n function removeLiquidityAVAX(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline\n ) external returns (uint256 amountToken, uint256 amountAVAX);\n\n function removeLiquidityWithPermit(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n address to,\n uint256 deadline,\n bool approveMax,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external returns (uint256 amountA, uint256 amountB);\n\n function removeLiquidityAVAXWithPermit(\n address token,\n uint256 liquidity,\n uint256 amountTokenMin,\n uint256 amountAVAXMin,\n address to,\n uint256 deadline,\n bool approveMax,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external returns (uint256 amountToken, uint256 amountAVAX);\n\n function swapExactTokensForTokens(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external returns (uint256[] memory amounts);\n\n function swapTokensForExactTokens(\n uint256 amountOut,\n uint256 amountInMax,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external returns (uint256[] memory amounts);\n\n function swapExactAVAXForTokens(\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external payable returns (uint256[] memory amounts);\n\n function swapTokensForExactAVAX(\n uint256 amountOut,\n uint256 amountInMax,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external returns (uint256[] memory amounts);\n\n function swapExactTokensForAVAX(\n uint256 amountIn,\n uint256 amountOutMin,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external returns (uint256[] memory amounts);\n\n function swapAVAXForExactTokens(\n uint256 amountOut,\n address[] calldata path,\n address to,\n uint256 deadline\n ) external payable returns (uint256[] memory amounts);\n\n function quote(\n uint256 amountA,\n uint256 reserveA,\n uint256 reserveB\n ) external pure returns (uint256 amountB);\n\n function getAmountOut(\n uint256 amountIn,\n uint256 reserveIn,\n uint256 reserveOut\n ) external pure returns (uint256 amountOut);\n\n function getAmountIn(\n uint256 amountOut,\n uint256 reserveIn,\n uint256 reserveOut\n ) external pure returns (uint256 amountIn);\n\n function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts);\n\n function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts);\n}\n" + }, + "contracts/Zap.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity =0.6.12;\n\n/*\n * Trader Joe\n * MIT License; modified from PancakeBunny\n *\n */\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\n\nimport \"./traderjoe/interfaces/IJoePair.sol\";\nimport \"./traderjoe/interfaces/IJoeRouter02.sol\";\nimport \"./traderjoe/interfaces/IWAVAX.sol\";\n\ncontract Zap is OwnableUpgradeable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n /* ========== CONSTANT VARIABLES ========== */\n\n address public JOE;\n address public constant USDT = 0xde3A24028580884448a5397872046a019649b084;\n address public constant DAI = 0xbA7dEebBFC5fA1100Fb055a87773e1E99Cd3507a;\n address public constant WAVAX = 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7;\n\n IJoeRouter02 private ROUTER;\n\n /* ========== STATE VARIABLES ========== */\n\n mapping(address => bool) private notLP;\n mapping(address => address) private routePairAddresses;\n address[] public tokens;\n\n /* ========== INITIALIZER ========== */\n\n function initialize(address _joe, address _router) external initializer {\n __Ownable_init();\n require(owner() != address(0), \"ZapETH: owner must be set\");\n\n JOE = _joe;\n ROUTER = IJoeRouter02(_router);\n setNotLP(WAVAX);\n setNotLP(USDT);\n setNotLP(JOE);\n setNotLP(DAI);\n }\n\n receive() external payable {}\n\n /* ========== View Functions ========== */\n\n function isLP(address _address) public view returns (bool) {\n return !notLP[_address];\n }\n\n function routePair(address _address) external view returns (address) {\n return routePairAddresses[_address];\n }\n\n /* ========== External Functions ========== */\n\n function zapInToken(\n address _from,\n uint256 amount,\n address _to\n ) external {\n IERC20(_from).safeTransferFrom(msg.sender, address(this), amount);\n _approveTokenIfNeeded(_from);\n\n if (isLP(_to)) {\n IJoePair pair = IJoePair(_to);\n address token0 = pair.token0();\n address token1 = pair.token1();\n if (_from == token0 || _from == token1) {\n // swap half amount for other\n address other = _from == token0 ? token1 : token0;\n _approveTokenIfNeeded(other);\n uint256 sellAmount = amount.div(2);\n uint256 otherAmount = _swap(_from, sellAmount, other, address(this));\n ROUTER.addLiquidity(\n _from,\n other,\n amount.sub(sellAmount),\n otherAmount,\n 0,\n 0,\n msg.sender,\n block.timestamp\n );\n } else {\n uint256 avaxAmount = _swapTokenForAVAX(_from, amount, address(this));\n _swapAVAXToLP(_to, avaxAmount, msg.sender);\n }\n } else {\n _swap(_from, amount, _to, msg.sender);\n }\n }\n\n function zapIn(address _to) external payable {\n _swapAVAXToLP(_to, msg.value, msg.sender);\n }\n\n function zapOut(address _from, uint256 amount) external {\n IERC20(_from).safeTransferFrom(msg.sender, address(this), amount);\n _approveTokenIfNeeded(_from);\n\n if (!isLP(_from)) {\n _swapTokenForAVAX(_from, amount, msg.sender);\n } else {\n IJoePair pair = IJoePair(_from);\n address token0 = pair.token0();\n address token1 = pair.token1();\n if (token0 == WAVAX || token1 == WAVAX) {\n ROUTER.removeLiquidityAVAX(\n token0 != WAVAX ? token0 : token1,\n amount,\n 0,\n 0,\n msg.sender,\n block.timestamp\n );\n } else {\n ROUTER.removeLiquidity(token0, token1, amount, 0, 0, msg.sender, block.timestamp);\n }\n }\n }\n\n /* ========== Private Functions ========== */\n\n function _approveTokenIfNeeded(address token) private {\n if (IERC20(token).allowance(address(this), address(ROUTER)) == 0) {\n IERC20(token).safeApprove(address(ROUTER), uint256(~0));\n }\n }\n\n function _swapAVAXToLP(\n address lp,\n uint256 amount,\n address receiver\n ) private {\n if (!isLP(lp)) {\n _swapAVAXForToken(lp, amount, receiver);\n } else {\n // lp\n IJoePair pair = IJoePair(lp);\n address token0 = pair.token0();\n address token1 = pair.token1();\n if (token0 == WAVAX || token1 == WAVAX) {\n address token = token0 == WAVAX ? token1 : token0;\n uint256 swapValue = amount.div(2);\n uint256 tokenAmount = _swapAVAXForToken(token, swapValue, address(this));\n\n _approveTokenIfNeeded(token);\n ROUTER.addLiquidityAVAX{value: amount.sub(swapValue)}(\n token,\n tokenAmount,\n 0,\n 0,\n receiver,\n block.timestamp\n );\n } else {\n uint256 swapValue = amount.div(2);\n uint256 token0Amount = _swapAVAXForToken(token0, swapValue, address(this));\n uint256 token1Amount = _swapAVAXForToken(token1, amount.sub(swapValue), address(this));\n\n _approveTokenIfNeeded(token0);\n _approveTokenIfNeeded(token1);\n ROUTER.addLiquidity(token0, token1, token0Amount, token1Amount, 0, 0, receiver, block.timestamp);\n }\n }\n }\n\n function _swapAVAXForToken(\n address token,\n uint256 value,\n address receiver\n ) private returns (uint256) {\n address[] memory path;\n\n if (routePairAddresses[token] != address(0)) {\n path = new address[](3);\n path[0] = WAVAX;\n path[1] = routePairAddresses[token];\n path[2] = token;\n } else {\n path = new address[](2);\n path[0] = WAVAX;\n path[1] = token;\n }\n\n uint256[] memory amounts = ROUTER.swapExactAVAXForTokens{value: value}(0, path, receiver, block.timestamp);\n return amounts[amounts.length - 1];\n }\n\n function _swapTokenForAVAX(\n address token,\n uint256 amount,\n address receiver\n ) private returns (uint256) {\n address[] memory path;\n if (routePairAddresses[token] != address(0)) {\n path = new address[](3);\n path[0] = token;\n path[1] = routePairAddresses[token];\n path[2] = WAVAX;\n } else {\n path = new address[](2);\n path[0] = token;\n path[1] = WAVAX;\n }\n\n uint256[] memory amounts = ROUTER.swapExactTokensForAVAX(amount, 0, path, receiver, block.timestamp);\n return amounts[amounts.length - 1];\n }\n\n function _swap(\n address _from,\n uint256 amount,\n address _to,\n address receiver\n ) private returns (uint256) {\n address intermediate = routePairAddresses[_from];\n if (intermediate == address(0)) {\n intermediate = routePairAddresses[_to];\n }\n\n address[] memory path;\n if (intermediate != address(0) && (_from == WAVAX || _to == WAVAX)) {\n // [WAVAX, BUSD, VAI] or [VAI, BUSD, WAVAX]\n path = new address[](3);\n path[0] = _from;\n path[1] = intermediate;\n path[2] = _to;\n } else if (intermediate != address(0) && (_from == intermediate || _to == intermediate)) {\n // [VAI, BUSD] or [BUSD, VAI]\n path = new address[](2);\n path[0] = _from;\n path[1] = _to;\n } else if (intermediate != address(0) && routePairAddresses[_from] == routePairAddresses[_to]) {\n // [VAI, DAI] or [VAI, USDC]\n path = new address[](3);\n path[0] = _from;\n path[1] = intermediate;\n path[2] = _to;\n } else if (\n routePairAddresses[_from] != address(0) &&\n routePairAddresses[_to] != address(0) &&\n routePairAddresses[_from] != routePairAddresses[_to]\n ) {\n // routePairAddresses[xToken] = xRoute\n // [VAI, BUSD, WAVAX, xRoute, xToken]\n path = new address[](5);\n path[0] = _from;\n path[1] = routePairAddresses[_from];\n path[2] = WAVAX;\n path[3] = routePairAddresses[_to];\n path[4] = _to;\n } else if (intermediate != address(0) && routePairAddresses[_from] != address(0)) {\n // [VAI, BUSD, WAVAX, BUNNY]\n path = new address[](4);\n path[0] = _from;\n path[1] = intermediate;\n path[2] = WAVAX;\n path[3] = _to;\n } else if (intermediate != address(0) && routePairAddresses[_to] != address(0)) {\n // [BUNNY, WAVAX, BUSD, VAI]\n path = new address[](4);\n path[0] = _from;\n path[1] = WAVAX;\n path[2] = intermediate;\n path[3] = _to;\n } else if (_from == WAVAX || _to == WAVAX) {\n // [WAVAX, BUNNY] or [BUNNY, WAVAX]\n path = new address[](2);\n path[0] = _from;\n path[1] = _to;\n } else {\n // [USDT, BUNNY] or [BUNNY, USDT]\n path = new address[](3);\n path[0] = _from;\n path[1] = WAVAX;\n path[2] = _to;\n }\n\n uint256[] memory amounts = ROUTER.swapExactTokensForTokens(amount, 0, path, receiver, block.timestamp);\n return amounts[amounts.length - 1];\n }\n\n /* ========== RESTRICTED FUNCTIONS ========== */\n\n function setRoutePairAddress(address asset, address route) external onlyOwner {\n routePairAddresses[asset] = route;\n }\n\n function setNotLP(address token) public onlyOwner {\n bool needPush = notLP[token] == false;\n notLP[token] = true;\n if (needPush) {\n tokens.push(token);\n }\n }\n\n function removeToken(uint256 i) external onlyOwner {\n address token = tokens[i];\n notLP[token] = false;\n tokens[i] = tokens[tokens.length - 1];\n tokens.pop();\n }\n\n function sweep() external onlyOwner {\n for (uint256 i = 0; i < tokens.length; i++) {\n address token = tokens[i];\n if (token == address(0)) continue;\n uint256 amount = IERC20(token).balanceOf(address(this));\n if (amount > 0) {\n if (token == WAVAX) {\n IWAVAX(token).withdraw(amount);\n } else {\n _swapTokenForAVAX(token, amount, owner());\n }\n }\n }\n\n uint256 balance = address(this).balance;\n if (balance > 0) {\n payable(owner()).transfer(balance);\n }\n }\n\n function withdraw(address token) external onlyOwner {\n if (token == address(0)) {\n payable(owner()).transfer(address(this).balance);\n return;\n }\n\n IERC20(token).transfer(owner(), IERC20(token).balanceOf(address(this)));\n }\n}\n" + }, + "@openzeppelin/contracts/math/SafeMath.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMath {\n /**\n * @dev Returns the addition of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n uint256 c = a + b;\n if (c < a) return (false, 0);\n return (true, c);\n }\n\n /**\n * @dev Returns the substraction of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n if (b > a) return (false, 0);\n return (true, a - b);\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) return (true, 0);\n uint256 c = a * b;\n if (c / a != b) return (false, 0);\n return (true, c);\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a division by zero flag.\n *\n * _Available since v3.4._\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n if (b == 0) return (false, 0);\n return (true, a / b);\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\n *\n * _Available since v3.4._\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n if (b == 0) return (false, 0);\n return (true, a % b);\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n *\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n return c;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b <= a, \"SafeMath: subtraction overflow\");\n return a - b;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n *\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n if (a == 0) return 0;\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n return c;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers, reverting on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b > 0, \"SafeMath: division by zero\");\n return a / b;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * reverting when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n require(b > 0, \"SafeMath: modulo by zero\");\n return a % b;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n * overflow (when the result is negative).\n *\n * CAUTION: This function is deprecated because it requires allocating memory for the error\n * message unnecessarily. For custom revert reasons use {trySub}.\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b <= a, errorMessage);\n return a - b;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers, reverting with custom message on\n * division by zero. The result is rounded towards zero.\n *\n * CAUTION: This function is deprecated because it requires allocating memory for the error\n * message unnecessarily. For custom revert reasons use {tryDiv}.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b > 0, errorMessage);\n return a / b;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * reverting with custom message when dividing by zero.\n *\n * CAUTION: This function is deprecated because it requires allocating memory for the error\n * message unnecessarily. For custom revert reasons use {tryMod}.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b > 0, errorMessage);\n return a % b;\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/SafeERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"../../math/SafeMath.sol\";\nimport \"../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using SafeMath for uint256;\n using Address for address;\n\n function safeTransfer(IERC20 token, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {IERC20-approve}, and its usage is discouraged.\n *\n * Whenever possible, use {safeIncreaseAllowance} and\n * {safeDecreaseAllowance} instead.\n */\n function safeApprove(IERC20 token, address spender, uint256 value) internal {\n // safeApprove should only be called when setting an initial allowance,\n // or when resetting it to zero. To increase and decrease it, use\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n // solhint-disable-next-line max-line-length\n require((value == 0) || (token.allowance(address(this), spender) == 0),\n \"SafeERC20: approve from non-zero to non-zero allowance\"\n );\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 newAllowance = token.allowance(address(this), spender).add(value);\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 newAllowance = token.allowance(address(this), spender).sub(value, \"SafeERC20: decreased allowance below zero\");\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n if (returndata.length > 0) { // Return data is optional\n // solhint-disable-next-line max-line-length\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `recipient`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address recipient, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `sender` to `recipient` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n" + }, + "@openzeppelin/contracts/utils/Address.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.2 <0.8.0;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize, which returns 0 for contracts in\n // construction, since the code is only stored at the end of the\n // constructor execution.\n\n uint256 size;\n // solhint-disable-next-line no-inline-assembly\n assembly { size := extcodesize(account) }\n return size > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\n (bool success, ) = recipient.call{ value: amount }(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain`call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, bytes memory returndata) = target.call{ value: value }(data);\n return _verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, bytes memory returndata) = target.staticcall(data);\n return _verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return _verifyCallResult(success, returndata, errorMessage);\n }\n\n function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n\n // solhint-disable-next-line no-inline-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n" + }, + "contracts/JoeRoll.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./traderjoe/interfaces/IJoePair.sol\";\nimport \"./traderjoe/interfaces/IJoeRouter01.sol\";\nimport \"./traderjoe/interfaces/IJoeFactory.sol\";\nimport \"./traderjoe/libraries/JoeLibrary.sol\";\n\n// JoeRoll helps your migrate your existing Uniswap LP tokens to TraderJoe LP ones\ncontract JoeRoll is Ownable {\n using SafeERC20 for IERC20;\n\n IJoeRouter01 public oldRouter;\n IJoeRouter01 public router;\n IERC20 public hatToken = IERC20(0x82FE038Ea4b50f9C957da326C412ebd73462077C);\n\n constructor(IJoeRouter01 _oldRouter, IJoeRouter01 _router) public {\n oldRouter = _oldRouter;\n router = _router;\n }\n\n function migrateWithPermit(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) public {\n IJoePair pair = IJoePair(pairForOldRouter(tokenA, tokenB));\n pair.permit(msg.sender, address(this), liquidity, deadline, v, r, s);\n\n migrate(tokenA, tokenB, liquidity, amountAMin, amountBMin, deadline);\n }\n\n // msg.sender should have approved 'liquidity' amount of LP token of 'tokenA' and 'tokenB'\n function migrate(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n uint256 deadline\n ) public {\n require(deadline >= block.timestamp, \"JoeSwap: EXPIRED\");\n\n // Remove liquidity from the old router with permit\n (uint256 amountA, uint256 amountB) = removeLiquidity(\n tokenA,\n tokenB,\n liquidity,\n amountAMin,\n amountBMin,\n deadline\n );\n\n // Add liquidity to the new router\n (uint256 pooledAmountA, uint256 pooledAmountB) = addLiquidity(tokenA, tokenB, amountA, amountB);\n\n // Send remaining tokens to msg.sender\n if (amountA > pooledAmountA) {\n IERC20(tokenA).safeTransfer(msg.sender, amountA - pooledAmountA);\n }\n if (amountB > pooledAmountB) {\n IERC20(tokenB).safeTransfer(msg.sender, amountB - pooledAmountB);\n }\n\n // Transfer user a single hat token if there are any remaining and user has not received one yet\n if (address(hatToken) != address(0)) {\n uint256 hatSupply = hatToken.balanceOf(address(this));\n uint256 userSupply = hatToken.balanceOf(msg.sender);\n if (hatSupply > 0 && userSupply == 0) {\n hatToken.safeTransfer(msg.sender, 1e18);\n }\n }\n }\n\n function removeLiquidity(\n address tokenA,\n address tokenB,\n uint256 liquidity,\n uint256 amountAMin,\n uint256 amountBMin,\n uint256 deadline\n ) internal returns (uint256 amountA, uint256 amountB) {\n IJoePair pair = IJoePair(pairForOldRouter(tokenA, tokenB));\n pair.transferFrom(msg.sender, address(pair), liquidity);\n (uint256 amount0, uint256 amount1) = pair.burn(address(this));\n (address token0, ) = JoeLibrary.sortTokens(tokenA, tokenB);\n (amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0);\n require(amountA >= amountAMin, \"JoeRoll: INSUFFICIENT_A_AMOUNT\");\n require(amountB >= amountBMin, \"JoeRoll: INSUFFICIENT_B_AMOUNT\");\n }\n\n // calculates the CREATE2 address for a pair without making any external calls\n function pairForOldRouter(address tokenA, address tokenB) internal view returns (address pair) {\n (address token0, address token1) = JoeLibrary.sortTokens(tokenA, tokenB);\n pair = address(\n uint256(\n keccak256(\n abi.encodePacked(\n hex\"ff\",\n oldRouter.factory(),\n keccak256(abi.encodePacked(token0, token1)),\n hex\"40231f6b438bce0797c9ada29b718a87ea0a5cea3fe9a771abdd76bd41a3e545\" // init code hash\n )\n )\n )\n );\n }\n\n function addLiquidity(\n address tokenA,\n address tokenB,\n uint256 amountADesired,\n uint256 amountBDesired\n ) internal returns (uint256 amountA, uint256 amountB) {\n (amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired);\n address pair = JoeLibrary.pairFor(router.factory(), tokenA, tokenB);\n IERC20(tokenA).safeTransfer(pair, amountA);\n IERC20(tokenB).safeTransfer(pair, amountB);\n IJoePair(pair).mint(msg.sender);\n }\n\n function _addLiquidity(\n address tokenA,\n address tokenB,\n uint256 amountADesired,\n uint256 amountBDesired\n ) internal returns (uint256 amountA, uint256 amountB) {\n // create the pair if it doesn't exist yet\n IJoeFactory factory = IJoeFactory(router.factory());\n if (factory.getPair(tokenA, tokenB) == address(0)) {\n factory.createPair(tokenA, tokenB);\n }\n (uint256 reserveA, uint256 reserveB) = JoeLibrary.getReserves(address(factory), tokenA, tokenB);\n if (reserveA == 0 && reserveB == 0) {\n (amountA, amountB) = (amountADesired, amountBDesired);\n } else {\n uint256 amountBOptimal = JoeLibrary.quote(amountADesired, reserveA, reserveB);\n if (amountBOptimal <= amountBDesired) {\n (amountA, amountB) = (amountADesired, amountBOptimal);\n } else {\n uint256 amountAOptimal = JoeLibrary.quote(amountBDesired, reserveB, reserveA);\n assert(amountAOptimal <= amountADesired);\n (amountA, amountB) = (amountAOptimal, amountBDesired);\n }\n }\n }\n}\n" + }, + "@openzeppelin/contracts/access/Ownable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../utils/Context.sol\";\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor () internal {\n address msgSender = _msgSender();\n _owner = msgSender;\n emit OwnershipTransferred(address(0), msgSender);\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n _;\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n emit OwnershipTransferred(_owner, address(0));\n _owner = address(0);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n emit OwnershipTransferred(_owner, newOwner);\n _owner = newOwner;\n }\n}\n" + }, + "@openzeppelin/contracts/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/*\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with GSN meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address payable) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes memory) {\n this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n return msg.data;\n }\n}\n" + }, + "contracts/MoneyMaker.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// P1 - P3: OK\npragma solidity 0.6.12;\n\nimport \"./libraries/SafeMath.sol\";\nimport \"./libraries/SafeERC20.sol\";\n\nimport \"./traderjoe/interfaces/IERC20.sol\";\nimport \"./traderjoe/interfaces/IJoePair.sol\";\nimport \"./traderjoe/interfaces/IJoeFactory.sol\";\nimport \"./traderjoe/libraries/JoeLibrary.sol\";\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/utils/EnumerableSet.sol\";\n\n/// @title Money Maker\n/// @author Trader Joe\n/// @notice MoneyMaker receives 0.05% of the swaps done on Trader Joe in the form of an LP. It swaps those LPs\n/// to a token of choice and sends it to the JoeBar\ncontract MoneyMaker is Ownable {\n using EnumerableSet for EnumerableSet.AddressSet;\n using SafeERC20 for IERC20;\n using SafeMath for uint256;\n\n IJoeFactory public immutable factory;\n\n address public immutable bar;\n address private immutable wavax;\n /// @notice Any ERC20\n address public tokenTo;\n /// @notice In basis points aka parts per 10,000 so 5000 is 50%, cap of 50%, default is 0\n uint256 public devCut = 0;\n address public devAddr;\n\n // @notice Set of addresses that can perform certain functions\n EnumerableSet.AddressSet private _isAuth;\n\n modifier onlyAuth() {\n require(_isAuth.contains(_msgSender()), \"MoneyMaker: FORBIDDEN\");\n _;\n }\n\n /// @dev Maps a token `token` to another token `bridge` so that it uses `token/bridge` pair to convert token\n mapping(address => address) internal _bridges;\n\n event AddAuthorizedAddress(address indexed _addr);\n event RemoveAuthorizedAddress(address indexed _addr);\n event SetDevAddr(address _addr);\n event SetDevCut(uint256 _amount);\n event SetTokenTo(address _tokenTo);\n event LogBridgeSet(address indexed token, address indexed oldBridge, address indexed bridge);\n event LogConvert(\n address indexed server,\n address indexed token0,\n address indexed token1,\n uint256 amount0,\n uint256 amount1,\n uint256 amountTOKEN\n );\n\n /// @notice Constructor\n /// @param _factory The address of JoeFactory\n /// @param _bar The address of JoeBar\n /// @param _tokenTo The address of the token we want to convert to\n /// @param _wavax The address of wavax\n constructor(\n address _factory,\n address _bar,\n address _tokenTo,\n address _wavax\n ) public {\n require(_factory != address(0), \"MoneyMaker: factory can't be address(0)\");\n require(_bar != address(0), \"MoneyMaker: bar can't be address(0)\");\n require(_tokenTo != address(0), \"MoneyMaker: token can't be address(0)\");\n require(_wavax != address(0), \"MoneyMaker: wavax can't be address(0)\");\n factory = IJoeFactory(_factory);\n bar = _bar;\n tokenTo = _tokenTo;\n wavax = _wavax;\n devAddr = _msgSender();\n _isAuth.add(_msgSender());\n }\n\n /// @notice Adds a user to the authorized addresses\n /// @param _auth The address to add\n function addAuth(address _auth) external onlyOwner {\n require(_isAuth.add(_auth), \"MoneyMaker: Address is already authorized\");\n emit AddAuthorizedAddress(_auth);\n }\n\n /// @notice Remove a user of authorized addresses\n /// @param _auth The address to remove\n function removeAuth(address _auth) external onlyOwner {\n require(_isAuth.remove(_auth), \"MoneyMaker: Address is not authorized\");\n emit RemoveAuthorizedAddress(_auth);\n }\n\n /// @notice Return the list of authorized addresses\n /// @param index Index of the returned address\n /// @return The authorized address at `index`\n function getAuth(uint256 index) external view returns (address) {\n return _isAuth.at(index);\n }\n\n /// @notice Return the length of authorized addresses\n /// @return The number of authorized addresses\n function lenAuth() external view returns (uint256) {\n return _isAuth.length();\n }\n\n /// @notice Force using `pair/bridge` pair to convert `token`\n /// @param token The address of the tokenFrom\n /// @param bridge The address of the tokenTo\n function setBridge(address token, address bridge) external onlyAuth {\n // Checks\n require(token != tokenTo && token != wavax && token != bridge, \"MoneyMaker: Invalid bridge\");\n\n // Effects\n address oldBridge = _bridges[token];\n _bridges[token] = bridge;\n emit LogBridgeSet(token, oldBridge, bridge);\n }\n\n /// @notice Sets dev cut, which will be sent to `devAddr`, can't be greater than 50%\n /// @param _amount The new devCut value\n function setDevCut(uint256 _amount) external onlyOwner {\n require(_amount <= 5000, \"setDevCut: cut too high\");\n devCut = _amount;\n\n emit SetDevCut(_amount);\n }\n\n /// @notice Sets `devAddr`, the address that will receive the `devCut`\n /// @param _addr The new dev address\n function setDevAddr(address _addr) external onlyOwner {\n require(_addr != address(0), \"setDevAddr, address cannot be zero address\");\n devAddr = _addr;\n\n emit SetDevAddr(_addr);\n }\n\n /// @notice Sets token that we're buying back\n /// @param _tokenTo The new token address\n function setTokenToAddress(address _tokenTo) external onlyOwner {\n require(_tokenTo != address(0), \"setTokenToAddress, address cannot be zero address\");\n tokenTo = _tokenTo;\n\n emit SetTokenTo(_tokenTo);\n }\n\n /// @notice Returns the `bridge` of a `token`\n /// @param token The tokenFrom address\n /// @return bridge The tokenTo address\n function bridgeFor(address token) public view returns (address bridge) {\n bridge = _bridges[token];\n if (bridge == address(0)) {\n bridge = wavax;\n }\n }\n\n // C6: It's not a fool proof solution, but it prevents flash loans, so here it's ok to use tx.origin\n modifier onlyEOA() {\n // Try to make flash-loan exploit harder to do by only allowing externally owned addresses.\n require(_msgSender() == tx.origin, \"MoneyMaker: must use EOA\");\n _;\n }\n\n /// @notice Converts a pair of tokens to tokenTo\n /// @dev _convert is separate to save gas by only checking the 'onlyEOA' modifier once in case of convertMultiple\n /// @param token0 The address of the first token of the pair that will be converted\n /// @param token1 The address of the second token of the pair that will be converted\n /// @param slippage The accepted slippage, in basis points aka parts per 10,000 so 5000 is 50%\n function convert(\n address token0,\n address token1,\n uint256 slippage\n ) external onlyEOA onlyAuth {\n require(slippage < 5_000, \"MoneyMaker: slippage needs to be lower than 50%\");\n _convert(token0, token1, slippage);\n }\n\n /// @notice Converts a list of pairs of tokens to tokenTo\n /// @dev _convert is separate to save gas by only checking the 'onlyEOA' modifier once in case of convertMultiple\n /// @param token0 The list of addresses of the first token of the pairs that will be converted\n /// @param token1 The list of addresses of the second token of the pairs that will be converted\n /// @param slippage The accepted slippage, in basis points aka parts per 10,000 so 5000 is 50%\n function convertMultiple(\n address[] calldata token0,\n address[] calldata token1,\n uint256 slippage\n ) external onlyEOA onlyAuth {\n // TODO: This can be optimized a fair bit, but this is safer and simpler for now\n require(slippage < 5_000, \"MoneyMaker: slippage needs to be lower than 50%\");\n require(token0.length == token1.length, \"MoneyMaker: arrays length don't match\");\n\n uint256 len = token0.length;\n for (uint256 i = 0; i < len; i++) {\n _convert(token0[i], token1[i], slippage);\n }\n }\n\n /// @notice Converts a pair of tokens to tokenTo\n /// @dev _convert is separate to save gas by only checking the 'onlyEOA' modifier once in case of convertMultiple\n /// @param token0 The address of the first token of the pair that is currently being converted\n /// @param token1 The address of the second token of the pair that is currently being converted\n /// @param slippage The accepted slippage, in basis points aka parts per 10,000 so 5000 is 50%\n function _convert(\n address token0,\n address token1,\n uint256 slippage\n ) internal {\n uint256 amount0;\n uint256 amount1;\n\n // handle case where non-LP tokens need to be converted\n if (token0 == token1) {\n amount0 = IERC20(token0).balanceOf(address(this));\n amount1 = 0;\n } else {\n IJoePair pair = IJoePair(factory.getPair(token0, token1));\n require(address(pair) != address(0), \"MoneyMaker: Invalid pair\");\n\n IERC20(address(pair)).safeTransfer(address(pair), pair.balanceOf(address(this)));\n\n // take balance of tokens in this contract before burning the pair, incase there are already some here\n uint256 tok0bal = IERC20(token0).balanceOf(address(this));\n uint256 tok1bal = IERC20(token1).balanceOf(address(this));\n\n pair.burn(address(this));\n\n // subtract old balance of tokens from new balance\n // the return values of pair.burn cant be trusted due to transfer tax tokens\n amount0 = IERC20(token0).balanceOf(address(this)).sub(tok0bal);\n amount1 = IERC20(token1).balanceOf(address(this)).sub(tok1bal);\n }\n emit LogConvert(\n _msgSender(),\n token0,\n token1,\n amount0,\n amount1,\n _convertStep(token0, token1, amount0, amount1, slippage)\n );\n }\n\n /// @notice Used to convert two tokens to `tokenTo`, step by step, called recursively\n /// @param token0 The address of the first token\n /// @param token1 The address of the second token\n /// @param amount0 The amount of the `token0`\n /// @param amount1 The amount of the `token1`\n /// @param slippage The accepted slippage, in basis points aka parts per 10,000 so 5000 is 50%\n /// @return tokenOut The amount of token\n function _convertStep(\n address token0,\n address token1,\n uint256 amount0,\n uint256 amount1,\n uint256 slippage\n ) internal returns (uint256 tokenOut) {\n // Interactions\n if (token0 == token1) {\n uint256 amount = amount0.add(amount1);\n if (token0 == tokenTo) {\n IERC20(tokenTo).safeTransfer(bar, amount);\n tokenOut = amount;\n } else if (token0 == wavax) {\n tokenOut = _toToken(wavax, amount, slippage);\n } else {\n address bridge = bridgeFor(token0);\n amount = _swap(token0, bridge, amount, address(this), slippage);\n tokenOut = _convertStep(bridge, bridge, amount, 0, slippage);\n }\n } else if (token0 == tokenTo) {\n // eg. TOKEN - AVAX\n IERC20(tokenTo).safeTransfer(bar, amount0);\n tokenOut = _toToken(token1, amount1, slippage).add(amount0);\n } else if (token1 == tokenTo) {\n // eg. USDT - TOKEN\n IERC20(tokenTo).safeTransfer(bar, amount1);\n tokenOut = _toToken(token0, amount0, slippage).add(amount1);\n } else if (token0 == wavax) {\n // eg. AVAX - USDC\n tokenOut = _toToken(wavax, _swap(token1, wavax, amount1, address(this), slippage).add(amount0), slippage);\n } else if (token1 == wavax) {\n // eg. USDT - AVAX\n tokenOut = _toToken(wavax, _swap(token0, wavax, amount0, address(this), slippage).add(amount1), slippage);\n } else {\n // eg. MIC - USDT\n address bridge0 = bridgeFor(token0);\n address bridge1 = bridgeFor(token1);\n if (bridge0 == token1) {\n // eg. MIC - USDT - and bridgeFor(MIC) = USDT\n tokenOut = _convertStep(\n bridge0,\n token1,\n _swap(token0, bridge0, amount0, address(this), slippage),\n amount1,\n slippage\n );\n } else if (bridge1 == token0) {\n // eg. WBTC - DSD - and bridgeFor(DSD) = WBTC\n tokenOut = _convertStep(\n token0,\n bridge1,\n amount0,\n _swap(token1, bridge1, amount1, address(this), slippage),\n slippage\n );\n } else {\n tokenOut = _convertStep(\n bridge0,\n bridge1, // eg. USDT - DSD - and bridgeFor(DSD) = WBTC\n _swap(token0, bridge0, amount0, address(this), slippage),\n _swap(token1, bridge1, amount1, address(this), slippage),\n slippage\n );\n }\n }\n }\n\n /// @notice Swaps `amountIn` `fromToken` to `toToken` and sends it to `to`, `amountOut` is required to be greater\n /// than allowed `slippage`\n /// @param fromToken The address of token that will be swapped\n /// @param toToken The address of the token that will be received\n /// @param amountIn The amount of the `fromToken`\n /// @param to The address that will receive the `toToken`\n /// @param slippage The accepted slippage, in basis points aka parts per 10,000 so 5000 is 50%\n /// @return amountOut The amount of `toToken` sent to `to`\n function _swap(\n address fromToken,\n address toToken,\n uint256 amountIn,\n address to,\n uint256 slippage\n ) internal returns (uint256 amountOut) {\n // Checks\n // X1 - X5: OK\n IJoePair pair = IJoePair(factory.getPair(fromToken, toToken));\n require(address(pair) != address(0), \"MoneyMaker: Cannot convert\");\n\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n (uint256 reserveInput, uint256 reserveOutput) = fromToken == pair.token0()\n ? (reserve0, reserve1)\n : (reserve1, reserve0);\n IERC20(fromToken).safeTransfer(address(pair), amountIn);\n uint256 amountInput = IERC20(fromToken).balanceOf(address(pair)).sub(reserveInput); // calculate amount that was transferred, this accounts for transfer taxes\n\n amountOut = JoeLibrary.getAmountOut(amountInput, reserveInput, reserveOutput);\n\n {\n uint256 rest = uint256(10_000).sub(slippage);\n /// @dev We simulate the amount received if we did a swapIn and swapOut without updating the reserves,\n /// hence why we do rest^2, i.e. calculating the slippage twice cause we actually do two swaps.\n /// This allows us to catch if a pair has low liquidity\n require(\n JoeLibrary.getAmountOut(amountOut, reserveOutput, reserveInput) >=\n amountInput.mul(rest).mul(rest).div(100_000_000),\n \"MoneyMaker: Slippage caught\"\n );\n }\n\n (uint256 amount0Out, uint256 amount1Out) = fromToken == pair.token0()\n ? (uint256(0), amountOut)\n : (amountOut, uint256(0));\n pair.swap(amount0Out, amount1Out, to, new bytes(0));\n }\n\n /// @notice Swaps an amount of token to another token, `tokenTo`\n /// @dev `amountOut` is required to be greater after slippage\n /// @param token The address of token that will be swapped\n /// @param amountIn The amount of the `token`\n /// @param slippage The accepted slippage, in basis points aka parts per 10,000 so 5000 is 50%\n /// @return amountOut The amount of `toToken` sent to JoeBar\n function _toToken(\n address token,\n uint256 amountIn,\n uint256 slippage\n ) internal returns (uint256 amountOut) {\n uint256 amount = amountIn;\n if (devCut > 0) {\n amount = amount.mul(devCut).div(10000);\n IERC20(token).safeTransfer(devAddr, amount);\n amount = amountIn.sub(amount);\n }\n amountOut = _swap(token, tokenTo, amount, bar, slippage);\n }\n}\n" + }, + "contracts/libraries/SafeMath.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\n// a library for performing overflow-safe math, updated with awesomeness from of DappHub (https://github.com/dapphub/ds-math)\nlibrary SafeMath {\n function add(uint256 a, uint256 b) internal pure returns (uint256 c) {\n require((c = a + b) >= b, \"SafeMath: Add Overflow\");\n }\n\n function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {\n require((c = a - b) <= a, \"SafeMath: Underflow\");\n }\n\n function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {\n require(b == 0 || (c = a * b) / b == a, \"SafeMath: Mul Overflow\");\n }\n\n function div(uint256 a, uint256 b) internal pure returns (uint256 c) {\n require(b > 0, \"SafeMath: Div by Zero\");\n c = a / b;\n }\n\n function to128(uint256 a) internal pure returns (uint128 c) {\n require(a <= uint128(-1), \"SafeMath: uint128 Overflow\");\n c = uint128(a);\n }\n}\n\nlibrary SafeMath128 {\n function add(uint128 a, uint128 b) internal pure returns (uint128 c) {\n require((c = a + b) >= b, \"SafeMath: Add Overflow\");\n }\n\n function sub(uint128 a, uint128 b) internal pure returns (uint128 c) {\n require((c = a - b) <= a, \"SafeMath: Underflow\");\n }\n}\n" + }, + "contracts/libraries/SafeERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\nimport \"../interfaces/IERC20.sol\";\n\nlibrary SafeERC20 {\n function safeSymbol(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x95d89b41));\n return success && data.length > 0 ? abi.decode(data, (string)) : \"???\";\n }\n\n function safeName(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x06fdde03));\n return success && data.length > 0 ? abi.decode(data, (string)) : \"???\";\n }\n\n function safeDecimals(IERC20 token) internal view returns (uint8) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x313ce567));\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\n }\n\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(0xa9059cbb, to, amount));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"SafeERC20: Transfer failed\");\n }\n\n function safeTransferFrom(\n IERC20 token,\n address from,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(\n abi.encodeWithSelector(0x23b872dd, from, address(this), amount)\n );\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"SafeERC20: TransferFrom failed\");\n }\n}\n" + }, + "@openzeppelin/contracts/utils/EnumerableSet.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n * // Add the library methods\n * using EnumerableSet for EnumerableSet.AddressSet;\n *\n * // Declare a set state variable\n * EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n */\nlibrary EnumerableSet {\n // To implement this library for multiple types with as little code\n // repetition as possible, we write it in terms of a generic Set type with\n // bytes32 values.\n // The Set implementation uses private functions, and user-facing\n // implementations (such as AddressSet) are just wrappers around the\n // underlying Set.\n // This means that we can only create new EnumerableSets for types that fit\n // in bytes32.\n\n struct Set {\n // Storage of set values\n bytes32[] _values;\n\n // Position of the value in the `values` array, plus 1 because index 0\n // means a value is not in the set.\n mapping (bytes32 => uint256) _indexes;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function _add(Set storage set, bytes32 value) private returns (bool) {\n if (!_contains(set, value)) {\n set._values.push(value);\n // The value is stored at length-1, but we add 1 to all indexes\n // and use 0 as a sentinel value\n set._indexes[value] = set._values.length;\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function _remove(Set storage set, bytes32 value) private returns (bool) {\n // We read and store the value's index to prevent multiple reads from the same storage slot\n uint256 valueIndex = set._indexes[value];\n\n if (valueIndex != 0) { // Equivalent to contains(set, value)\n // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n // the array, and then remove the last element (sometimes called as 'swap and pop').\n // This modifies the order of the array, as noted in {at}.\n\n uint256 toDeleteIndex = valueIndex - 1;\n uint256 lastIndex = set._values.length - 1;\n\n // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs\n // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.\n\n bytes32 lastvalue = set._values[lastIndex];\n\n // Move the last value to the index where the value to delete is\n set._values[toDeleteIndex] = lastvalue;\n // Update the index for the moved value\n set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based\n\n // Delete the slot where the moved value was stored\n set._values.pop();\n\n // Delete the index for the deleted slot\n delete set._indexes[value];\n\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function _contains(Set storage set, bytes32 value) private view returns (bool) {\n return set._indexes[value] != 0;\n }\n\n /**\n * @dev Returns the number of values on the set. O(1).\n */\n function _length(Set storage set) private view returns (uint256) {\n return set._values.length;\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function _at(Set storage set, uint256 index) private view returns (bytes32) {\n require(set._values.length > index, \"EnumerableSet: index out of bounds\");\n return set._values[index];\n }\n\n // Bytes32Set\n\n struct Bytes32Set {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _add(set._inner, value);\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _remove(set._inner, value);\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n return _contains(set._inner, value);\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(Bytes32Set storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n return _at(set._inner, index);\n }\n\n // AddressSet\n\n struct AddressSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(AddressSet storage set, address value) internal returns (bool) {\n return _add(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(AddressSet storage set, address value) internal returns (bool) {\n return _remove(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(AddressSet storage set, address value) internal view returns (bool) {\n return _contains(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(AddressSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(AddressSet storage set, uint256 index) internal view returns (address) {\n return address(uint160(uint256(_at(set._inner, index))));\n }\n\n\n // UintSet\n\n struct UintSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(UintSet storage set, uint256 value) internal returns (bool) {\n return _add(set._inner, bytes32(value));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(UintSet storage set, uint256 value) internal returns (bool) {\n return _remove(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n return _contains(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns the number of values on the set. O(1).\n */\n function length(UintSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n return uint256(_at(set._inner, index));\n }\n}\n" + }, + "contracts/sushi/MasterChefPerSec.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/utils/EnumerableSet.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./SushiToken.sol\";\n\n// MasterChef is the master of Sushi. He can make Sushi and he is a fair guy.\n//\n// Note that it's ownable and the owner wields tremendous power. The ownership\n// will be transferred to a governance smart contract once SUSHI is sufficiently\n// distributed and the community can show to govern itself.\n//\n// Have fun reading it. Hopefully it's bug-free. God bless.\ncontract MasterChefPerSec is Ownable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n // Info of each user.\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n //\n // We do some fancy math here. Basically, any point in time, the amount of SUSHIs\n // entitled to a user but is pending to be distributed is:\n //\n // pending reward = (user.amount * pool.accSushiPerShare) - user.rewardDebt\n //\n // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:\n // 1. The pool's `accSushiPerShare` (and `lastRewardBlock`) gets updated.\n // 2. User receives the pending reward sent to his/her address.\n // 3. User's `amount` gets updated.\n // 4. User's `rewardDebt` gets updated.\n }\n // Info of each pool.\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. SUSHIs to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that SUSHIs distribution occurs.\n uint256 accSushiPerShare; // Accumulated SUSHIs per share, times 1e12. See below.\n }\n // The SUSHI TOKEN!\n SushiToken public sushi;\n // Dev address.\n address public devaddr;\n // Block number when bonus SUSHI period ends.\n uint256 public bonusEndTimestamp;\n // SUSHI tokens created per block.\n uint256 public sushiPerSec;\n // Bonus muliplier for early sushi makers.\n uint256 public constant BONUS_MULTIPLIER = 1;\n // Info of each pool.\n PoolInfo[] public poolInfo;\n // Info of each user that stakes LP tokens.\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n // Total allocation poitns. Must be the sum of all allocation points in all pools.\n uint256 public totalAllocPoint = 0;\n // The block number when SUSHI mining starts.\n uint256 public startTimestamp;\n event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\n event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\n\n constructor(\n SushiToken _sushi,\n address _devaddr,\n uint256 _sushiPerSec,\n uint256 _startTimestamp,\n uint256 _bonusEndTimestamp\n ) public {\n sushi = _sushi;\n devaddr = _devaddr;\n sushiPerSec = _sushiPerSec;\n bonusEndTimestamp = _bonusEndTimestamp;\n startTimestamp = _startTimestamp;\n }\n\n function poolLength() external view returns (uint256) {\n return poolInfo.length;\n }\n\n // Add a new lp to the pool. Can only be called by the owner.\n // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.\n function add(\n uint256 _allocPoint,\n IERC20 _lpToken,\n bool _withUpdate\n ) public onlyOwner {\n if (_withUpdate) {\n massUpdatePools();\n }\n uint256 lastRewardTimestamp = block.timestamp > startTimestamp ? block.timestamp : startTimestamp;\n totalAllocPoint = totalAllocPoint.add(_allocPoint);\n poolInfo.push(\n PoolInfo({\n lpToken: _lpToken,\n allocPoint: _allocPoint,\n lastRewardTimestamp: lastRewardTimestamp,\n accSushiPerShare: 0\n })\n );\n }\n\n // Update the given pool's SUSHI allocation point. Can only be called by the owner.\n function set(\n uint256 _pid,\n uint256 _allocPoint,\n bool _withUpdate\n ) public onlyOwner {\n if (_withUpdate) {\n massUpdatePools();\n }\n totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);\n poolInfo[_pid].allocPoint = _allocPoint;\n }\n\n // Return reward multiplier over the given _from to _to block.\n function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) {\n if (_to <= bonusEndTimestamp) {\n return _to.sub(_from).mul(BONUS_MULTIPLIER);\n } else if (_from >= bonusEndTimestamp) {\n return _to.sub(_from);\n } else {\n return bonusEndTimestamp.sub(_from).mul(BONUS_MULTIPLIER).add(_to.sub(bonusEndTimestamp));\n }\n }\n\n // View function to see pending SUSHIs on frontend.\n function pendingSushi(uint256 _pid, address _user) external view returns (uint256) {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_user];\n uint256 accSushiPerShare = pool.accSushiPerShare;\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (block.timestamp > pool.lastRewardTimestamp && lpSupply != 0) {\n uint256 multiplier = getMultiplier(pool.lastRewardTimestamp, block.timestamp);\n uint256 sushiReward = multiplier.mul(sushiPerSec).mul(pool.allocPoint).div(totalAllocPoint);\n accSushiPerShare = accSushiPerShare.add(sushiReward.mul(1e12).div(lpSupply));\n }\n return user.amount.mul(accSushiPerShare).div(1e12).sub(user.rewardDebt);\n }\n\n // Update reward vairables for all pools. Be careful of gas spending!\n function massUpdatePools() public {\n uint256 length = poolInfo.length;\n for (uint256 pid = 0; pid < length; ++pid) {\n updatePool(pid);\n }\n }\n\n // Update reward variables of the given pool to be up-to-date.\n function updatePool(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n if (block.timestamp <= pool.lastRewardTimestamp) {\n return;\n }\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (lpSupply == 0) {\n pool.lastRewardTimestamp = block.timestamp;\n return;\n }\n uint256 multiplier = getMultiplier(pool.lastRewardTimestamp, block.timestamp);\n uint256 sushiReward = multiplier.mul(sushiPerSec).mul(pool.allocPoint).div(totalAllocPoint);\n sushi.mint(devaddr, sushiReward.div(10));\n sushi.mint(address(this), sushiReward);\n pool.accSushiPerShare = pool.accSushiPerShare.add(sushiReward.mul(1e12).div(lpSupply));\n pool.lastRewardTimestamp = block.timestamp;\n }\n\n // Deposit LP tokens to MasterChef for SUSHI allocation.\n function deposit(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n updatePool(_pid);\n if (user.amount > 0) {\n uint256 pending = user.amount.mul(pool.accSushiPerShare).div(1e12).sub(user.rewardDebt);\n safeSushiTransfer(msg.sender, pending);\n }\n pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);\n user.amount = user.amount.add(_amount);\n user.rewardDebt = user.amount.mul(pool.accSushiPerShare).div(1e12);\n emit Deposit(msg.sender, _pid, _amount);\n }\n\n // Withdraw LP tokens from MasterChef.\n function withdraw(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n require(user.amount >= _amount, \"withdraw: not good\");\n updatePool(_pid);\n uint256 pending = user.amount.mul(pool.accSushiPerShare).div(1e12).sub(user.rewardDebt);\n safeSushiTransfer(msg.sender, pending);\n user.amount = user.amount.sub(_amount);\n user.rewardDebt = user.amount.mul(pool.accSushiPerShare).div(1e12);\n pool.lpToken.safeTransfer(address(msg.sender), _amount);\n emit Withdraw(msg.sender, _pid, _amount);\n }\n\n // Withdraw without caring about rewards. EMERGENCY ONLY.\n function emergencyWithdraw(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n pool.lpToken.safeTransfer(address(msg.sender), user.amount);\n emit EmergencyWithdraw(msg.sender, _pid, user.amount);\n user.amount = 0;\n user.rewardDebt = 0;\n }\n\n // Safe sushi transfer function, just in case if rounding error causes pool to not have enough SUSHIs.\n function safeSushiTransfer(address _to, uint256 _amount) internal {\n uint256 sushiBal = sushi.balanceOf(address(this));\n if (_amount > sushiBal) {\n sushi.transfer(_to, sushiBal);\n } else {\n sushi.transfer(_to, _amount);\n }\n }\n\n // Update dev address by the previous dev.\n function dev(address _devaddr) public {\n require(msg.sender == devaddr, \"dev: wut?\");\n devaddr = _devaddr;\n }\n}\n" + }, + "contracts/sushi/SushiToken.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\n// SushiToken with Governance.\ncontract SushiToken is ERC20(\"SushiToken\", \"SUSHI\"), Ownable {\n /// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef).\n function mint(address _to, uint256 _amount) public onlyOwner {\n _mint(_to, _amount);\n _moveDelegates(address(0), _delegates[_to], _amount);\n }\n\n // Copied and modified from YAM code:\n // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol\n // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol\n // Which is copied and modified from COMPOUND:\n // https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol\n\n /// @notice A record of each accounts delegate\n mapping(address => address) internal _delegates;\n\n /// @notice A checkpoint for marking number of votes from a given block\n struct Checkpoint {\n uint32 fromBlock;\n uint256 votes;\n }\n\n /// @notice A record of votes checkpoints for each account, by index\n mapping(address => mapping(uint32 => Checkpoint)) public checkpoints;\n\n /// @notice The number of checkpoints for each account\n mapping(address => uint32) public numCheckpoints;\n\n /// @notice The EIP-712 typehash for the contract's domain\n bytes32 public constant DOMAIN_TYPEHASH =\n keccak256(\"EIP712Domain(string name,uint256 chainId,address verifyingContract)\");\n\n /// @notice The EIP-712 typehash for the delegation struct used by the contract\n bytes32 public constant DELEGATION_TYPEHASH =\n keccak256(\"Delegation(address delegatee,uint256 nonce,uint256 expiry)\");\n\n /// @notice A record of states for signing / validating signatures\n mapping(address => uint256) public nonces;\n\n /// @notice An event thats emitted when an account changes its delegate\n event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);\n\n /// @notice An event thats emitted when a delegate account's vote balance changes\n event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);\n\n /**\n * @notice Delegate votes from `msg.sender` to `delegatee`\n * @param delegator The address to get delegatee for\n */\n function delegates(address delegator) external view returns (address) {\n return _delegates[delegator];\n }\n\n /**\n * @notice Delegate votes from `msg.sender` to `delegatee`\n * @param delegatee The address to delegate votes to\n */\n function delegate(address delegatee) external {\n return _delegate(msg.sender, delegatee);\n }\n\n /**\n * @notice Delegates votes from signatory to `delegatee`\n * @param delegatee The address to delegate votes to\n * @param nonce The contract state required to match the signature\n * @param expiry The time at which to expire the signature\n * @param v The recovery byte of the signature\n * @param r Half of the ECDSA signature pair\n * @param s Half of the ECDSA signature pair\n */\n function delegateBySig(\n address delegatee,\n uint256 nonce,\n uint256 expiry,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external {\n bytes32 domainSeparator = keccak256(\n abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name())), getChainId(), address(this))\n );\n\n bytes32 structHash = keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry));\n\n bytes32 digest = keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\n\n address signatory = ecrecover(digest, v, r, s);\n require(signatory != address(0), \"SUSHI::delegateBySig: invalid signature\");\n require(nonce == nonces[signatory]++, \"SUSHI::delegateBySig: invalid nonce\");\n require(now <= expiry, \"SUSHI::delegateBySig: signature expired\");\n return _delegate(signatory, delegatee);\n }\n\n /**\n * @notice Gets the current votes balance for `account`\n * @param account The address to get votes balance\n * @return The number of current votes for `account`\n */\n function getCurrentVotes(address account) external view returns (uint256) {\n uint32 nCheckpoints = numCheckpoints[account];\n return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;\n }\n\n /**\n * @notice Determine the prior number of votes for an account as of a block number\n * @dev Block number must be a finalized block or else this function will revert to prevent misinformation.\n * @param account The address of the account to check\n * @param blockNumber The block number to get the vote balance at\n * @return The number of votes the account had as of the given block\n */\n function getPriorVotes(address account, uint256 blockNumber) external view returns (uint256) {\n require(blockNumber < block.number, \"SUSHI::getPriorVotes: not yet determined\");\n\n uint32 nCheckpoints = numCheckpoints[account];\n if (nCheckpoints == 0) {\n return 0;\n }\n\n // First check most recent balance\n if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {\n return checkpoints[account][nCheckpoints - 1].votes;\n }\n\n // Next check implicit zero balance\n if (checkpoints[account][0].fromBlock > blockNumber) {\n return 0;\n }\n\n uint32 lower = 0;\n uint32 upper = nCheckpoints - 1;\n while (upper > lower) {\n uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow\n Checkpoint memory cp = checkpoints[account][center];\n if (cp.fromBlock == blockNumber) {\n return cp.votes;\n } else if (cp.fromBlock < blockNumber) {\n lower = center;\n } else {\n upper = center - 1;\n }\n }\n return checkpoints[account][lower].votes;\n }\n\n function _delegate(address delegator, address delegatee) internal {\n address currentDelegate = _delegates[delegator];\n uint256 delegatorBalance = balanceOf(delegator); // balance of underlying SUSHIs (not scaled);\n _delegates[delegator] = delegatee;\n\n emit DelegateChanged(delegator, currentDelegate, delegatee);\n\n _moveDelegates(currentDelegate, delegatee, delegatorBalance);\n }\n\n function _moveDelegates(\n address srcRep,\n address dstRep,\n uint256 amount\n ) internal {\n if (srcRep != dstRep && amount > 0) {\n if (srcRep != address(0)) {\n // decrease old representative\n uint32 srcRepNum = numCheckpoints[srcRep];\n uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;\n uint256 srcRepNew = srcRepOld.sub(amount);\n _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);\n }\n\n if (dstRep != address(0)) {\n // increase new representative\n uint32 dstRepNum = numCheckpoints[dstRep];\n uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;\n uint256 dstRepNew = dstRepOld.add(amount);\n _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);\n }\n }\n }\n\n function _writeCheckpoint(\n address delegatee,\n uint32 nCheckpoints,\n uint256 oldVotes,\n uint256 newVotes\n ) internal {\n uint32 blockNumber = safe32(block.number, \"SUSHI::_writeCheckpoint: block number exceeds 32 bits\");\n\n if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {\n checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;\n } else {\n checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);\n numCheckpoints[delegatee] = nCheckpoints + 1;\n }\n\n emit DelegateVotesChanged(delegatee, oldVotes, newVotes);\n }\n\n function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) {\n require(n < 2**32, errorMessage);\n return uint32(n);\n }\n\n function getChainId() internal pure returns (uint256) {\n uint256 chainId;\n assembly {\n chainId := chainid()\n }\n return chainId;\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/ERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../../utils/Context.sol\";\nimport \"./IERC20.sol\";\nimport \"../../math/SafeMath.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin guidelines: functions revert instead\n * of returning `false` on failure. This behavior is nonetheless conventional\n * and does not conflict with the expectations of ERC20 applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20 {\n using SafeMath for uint256;\n\n mapping (address => uint256) private _balances;\n\n mapping (address => mapping (address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n uint8 private _decimals;\n\n /**\n * @dev Sets the values for {name} and {symbol}, initializes {decimals} with\n * a default value of 18.\n *\n * To select a different value for {decimals}, use {_setupDecimals}.\n *\n * All three of these values are immutable: they can only be set once during\n * construction.\n */\n constructor (string memory name_, string memory symbol_) public {\n _name = name_;\n _symbol = symbol_;\n _decimals = 18;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5,05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is\n * called.\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual returns (uint8) {\n return _decimals;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `recipient` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address recipient, uint256 amount) public virtual override returns (bool) {\n _transfer(_msgSender(), recipient, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n _approve(_msgSender(), spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * Requirements:\n *\n * - `sender` and `recipient` cannot be the zero address.\n * - `sender` must have a balance of at least `amount`.\n * - the caller must have allowance for ``sender``'s tokens of at least\n * `amount`.\n */\n function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {\n _transfer(sender, recipient, amount);\n _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, \"ERC20: transfer amount exceeds allowance\"));\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, \"ERC20: decreased allowance below zero\"));\n return true;\n }\n\n /**\n * @dev Moves tokens `amount` from `sender` to `recipient`.\n *\n * This is internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `sender` cannot be the zero address.\n * - `recipient` cannot be the zero address.\n * - `sender` must have a balance of at least `amount`.\n */\n function _transfer(address sender, address recipient, uint256 amount) internal virtual {\n require(sender != address(0), \"ERC20: transfer from the zero address\");\n require(recipient != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(sender, recipient, amount);\n\n _balances[sender] = _balances[sender].sub(amount, \"ERC20: transfer amount exceeds balance\");\n _balances[recipient] = _balances[recipient].add(amount);\n emit Transfer(sender, recipient, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply = _totalSupply.add(amount);\n _balances[account] = _balances[account].add(amount);\n emit Transfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n _balances[account] = _balances[account].sub(amount, \"ERC20: burn amount exceeds balance\");\n _totalSupply = _totalSupply.sub(amount);\n emit Transfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(address owner, address spender, uint256 amount) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Sets {decimals} to a value other than the default one of 18.\n *\n * WARNING: This function should only be called from the constructor. Most\n * applications that interact with token contracts will not expect\n * {decimals} to ever change, and may work incorrectly if it does.\n */\n function _setupDecimals(uint8 decimals_) internal virtual {\n _decimals = decimals_;\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be to transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }\n}\n" + }, + "contracts/mocks/ERC20MockDecimals.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\n/// @title ERC20MockDecimals\n/// @author Trader Joe\n/// @dev ONLY FOR TESTS\ncontract ERC20MockDecimals is ERC20, Ownable {\n uint8 private decimalsOverride;\n\n /// @dev Constructor\n /// @param _decimals The number of decimals for this token\n constructor(uint8 _decimals) public ERC20(\"ERC20Mock\", \"ERC20M\") {\n decimalsOverride = _decimals;\n }\n\n /// @dev Define the number of decimals\n /// @return The number of decimals\n function decimals() public view override returns (uint8) {\n return decimalsOverride;\n }\n\n /// @dev Mint _amount to _to. Callable only by owner\n /// @param _to The address that will receive the mint\n /// @param _amount The amount to be minted\n function mint(address _to, uint256 _amount) external {\n _mint(_to, _amount);\n }\n}\n" + }, + "contracts/mocks/ERC20Mock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract ERC20Mock is ERC20, Ownable {\n constructor(\n string memory name,\n string memory symbol,\n uint256 supply\n ) public ERC20(name, symbol) {\n _mint(msg.sender, supply);\n }\n}\n" + }, + "contracts/JoeToken.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\n// JoeToken with Governance.\ncontract JoeToken is ERC20(\"JoeToken\", \"JOE\"), Ownable {\n /// @notice Total number of tokens\n uint256 public maxSupply = 500_000_000e18; // 500 million Joe\n\n /// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterJoe).\n function mint(address _to, uint256 _amount) public onlyOwner {\n require(totalSupply().add(_amount) <= maxSupply, \"JOE::mint: cannot exceed max supply\");\n _mint(_to, _amount);\n _moveDelegates(address(0), _delegates[_to], _amount);\n }\n\n // Copied and modified from YAM code:\n // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol\n // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol\n // Which is copied and modified from COMPOUND:\n // https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol\n\n /// @notice A record of each accounts delegate\n mapping(address => address) internal _delegates;\n\n /// @notice A checkpoint for marking number of votes from a given block\n struct Checkpoint {\n uint32 fromBlock;\n uint256 votes;\n }\n\n /// @notice A record of votes checkpoints for each account, by index\n mapping(address => mapping(uint32 => Checkpoint)) public checkpoints;\n\n /// @notice The number of checkpoints for each account\n mapping(address => uint32) public numCheckpoints;\n\n /// @notice The EIP-712 typehash for the contract's domain\n bytes32 public constant DOMAIN_TYPEHASH =\n keccak256(\"EIP712Domain(string name,uint256 chainId,address verifyingContract)\");\n\n /// @notice The EIP-712 typehash for the delegation struct used by the contract\n bytes32 public constant DELEGATION_TYPEHASH =\n keccak256(\"Delegation(address delegatee,uint256 nonce,uint256 expiry)\");\n\n /// @notice A record of states for signing / validating signatures\n mapping(address => uint256) public nonces;\n\n /// @notice An event thats emitted when an account changes its delegate\n event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);\n\n /// @notice An event thats emitted when a delegate account's vote balance changes\n event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);\n\n /**\n * @notice Delegate votes from `msg.sender` to `delegatee`\n * @param delegator The address to get delegatee for\n */\n function delegates(address delegator) external view returns (address) {\n return _delegates[delegator];\n }\n\n /**\n * @notice Delegate votes from `msg.sender` to `delegatee`\n * @param delegatee The address to delegate votes to\n */\n function delegate(address delegatee) external {\n return _delegate(msg.sender, delegatee);\n }\n\n /**\n * @notice Delegates votes from signatory to `delegatee`\n * @param delegatee The address to delegate votes to\n * @param nonce The contract state required to match the signature\n * @param expiry The time at which to expire the signature\n * @param v The recovery byte of the signature\n * @param r Half of the ECDSA signature pair\n * @param s Half of the ECDSA signature pair\n */\n function delegateBySig(\n address delegatee,\n uint256 nonce,\n uint256 expiry,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external {\n bytes32 domainSeparator = keccak256(\n abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name())), getChainId(), address(this))\n );\n\n bytes32 structHash = keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry));\n\n bytes32 digest = keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\n\n address signatory = ecrecover(digest, v, r, s);\n require(signatory != address(0), \"JOE::delegateBySig: invalid signature\");\n require(nonce == nonces[signatory]++, \"JOE::delegateBySig: invalid nonce\");\n require(now <= expiry, \"JOE::delegateBySig: signature expired\");\n return _delegate(signatory, delegatee);\n }\n\n /**\n * @notice Gets the current votes balance for `account`\n * @param account The address to get votes balance\n * @return The number of current votes for `account`\n */\n function getCurrentVotes(address account) external view returns (uint256) {\n uint32 nCheckpoints = numCheckpoints[account];\n return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;\n }\n\n /**\n * @notice Determine the prior number of votes for an account as of a block number\n * @dev Block number must be a finalized block or else this function will revert to prevent misinformation.\n * @param account The address of the account to check\n * @param blockNumber The block number to get the vote balance at\n * @return The number of votes the account had as of the given block\n */\n function getPriorVotes(address account, uint256 blockNumber) external view returns (uint256) {\n require(blockNumber < block.number, \"JOE::getPriorVotes: not yet determined\");\n\n uint32 nCheckpoints = numCheckpoints[account];\n if (nCheckpoints == 0) {\n return 0;\n }\n\n // First check most recent balance\n if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {\n return checkpoints[account][nCheckpoints - 1].votes;\n }\n\n // Next check implicit zero balance\n if (checkpoints[account][0].fromBlock > blockNumber) {\n return 0;\n }\n\n uint32 lower = 0;\n uint32 upper = nCheckpoints - 1;\n while (upper > lower) {\n uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow\n Checkpoint memory cp = checkpoints[account][center];\n if (cp.fromBlock == blockNumber) {\n return cp.votes;\n } else if (cp.fromBlock < blockNumber) {\n lower = center;\n } else {\n upper = center - 1;\n }\n }\n return checkpoints[account][lower].votes;\n }\n\n function _delegate(address delegator, address delegatee) internal {\n address currentDelegate = _delegates[delegator];\n uint256 delegatorBalance = balanceOf(delegator); // balance of underlying JOEs (not scaled);\n _delegates[delegator] = delegatee;\n\n emit DelegateChanged(delegator, currentDelegate, delegatee);\n\n _moveDelegates(currentDelegate, delegatee, delegatorBalance);\n }\n\n function _moveDelegates(\n address srcRep,\n address dstRep,\n uint256 amount\n ) internal {\n if (srcRep != dstRep && amount > 0) {\n if (srcRep != address(0)) {\n // decrease old representative\n uint32 srcRepNum = numCheckpoints[srcRep];\n uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;\n uint256 srcRepNew = srcRepOld.sub(amount);\n _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);\n }\n\n if (dstRep != address(0)) {\n // increase new representative\n uint32 dstRepNum = numCheckpoints[dstRep];\n uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;\n uint256 dstRepNew = dstRepOld.add(amount);\n _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);\n }\n }\n }\n\n function _writeCheckpoint(\n address delegatee,\n uint32 nCheckpoints,\n uint256 oldVotes,\n uint256 newVotes\n ) internal {\n uint32 blockNumber = safe32(block.number, \"JOE::_writeCheckpoint: block number exceeds 32 bits\");\n\n if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {\n checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;\n } else {\n checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);\n numCheckpoints[delegatee] = nCheckpoints + 1;\n }\n\n emit DelegateVotesChanged(delegatee, oldVotes, newVotes);\n }\n\n function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) {\n require(n < 2**32, errorMessage);\n return uint32(n);\n }\n\n function getChainId() internal pure returns (uint256) {\n uint256 chainId;\n assembly {\n chainId := chainid()\n }\n return chainId;\n }\n}\n" + }, + "contracts/MasterChefJoeV2.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/utils/EnumerableSet.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./JoeToken.sol\";\nimport \"./libraries/BoringERC20.sol\";\n\n\ninterface IRewarder {\n using SafeERC20 for IERC20;\n\n function onJoeReward(address user, uint256 newLpAmount) external;\n\n function pendingTokens(address user) external view returns (uint256 pending);\n\n function rewardToken() external view returns (address);\n}\n\n// MasterChefJoe is a boss. He says \"go f your blocks lego boy, I'm gonna use timestamp instead\".\n// And to top it off, it takes no risks. Because the biggest risk is operator error.\n// So we make it virtually impossible for the operator of this contract to cause a bug with people's harvests.\n//\n// Note that it's ownable and the owner wields tremendous power. The ownership\n// will be transferred to a governance smart contract once JOE is sufficiently\n// distributed and the community can show to govern itself.\n//\n// With thanks to the Lydia Finance team.\n//\n// Godspeed and may the 10x be with you.\ncontract MasterChefJoeV2 is Ownable {\n using SafeMath for uint256;\n using BoringERC20 for IERC20;\n using EnumerableSet for EnumerableSet.AddressSet;\n\n // Info of each user.\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n //\n // We do some fancy math here. Basically, any point in time, the amount of JOEs\n // entitled to a user but is pending to be distributed is:\n //\n // pending reward = (user.amount * pool.accJoePerShare) - user.rewardDebt\n //\n // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:\n // 1. The pool's `accJoePerShare` (and `lastRewardTimestamp`) gets updated.\n // 2. User receives the pending reward sent to his/her address.\n // 3. User's `amount` gets updated.\n // 4. User's `rewardDebt` gets updated.\n }\n\n // Info of each pool.\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOEs to distribute per second.\n uint256 lastRewardTimestamp; // Last timestamp that JOEs distribution occurs.\n uint256 accJoePerShare; // Accumulated JOEs per share, times 1e12. See below.\n IRewarder rewarder;\n }\n\n // The JOE TOKEN!\n JoeToken public joe;\n // Dev address.\n address public devAddr;\n // Treasury address.\n address public treasuryAddr;\n // Investor address\n address public investorAddr;\n // JOE tokens created per second.\n uint256 public joePerSec;\n // Percentage of pool rewards that goto the devs.\n uint256 public devPercent;\n // Percentage of pool rewards that goes to the treasury.\n uint256 public treasuryPercent;\n // Percentage of pool rewards that goes to the investor.\n uint256 public investorPercent;\n\n // Info of each pool.\n PoolInfo[] public poolInfo;\n // Set of all LP tokens that have been added as pools\n EnumerableSet.AddressSet private lpTokens;\n // Info of each user that stakes LP tokens.\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n // Total allocation points. Must be the sum of all allocation points in all pools.\n uint256 public totalAllocPoint;\n // The timestamp when JOE mining starts.\n uint256 public startTimestamp;\n\n event Add(uint256 indexed pid, uint256 allocPoint, IERC20 indexed lpToken, IRewarder indexed rewarder);\n event Set(uint256 indexed pid, uint256 allocPoint, IRewarder indexed rewarder, bool overwrite);\n event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\n event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event UpdatePool(uint256 indexed pid, uint256 lastRewardTimestamp, uint256 lpSupply, uint256 accJoePerShare);\n event Harvest(address indexed user, uint256 indexed pid, uint256 amount);\n event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event SetDevAddress(address indexed oldAddress, address indexed newAddress);\n event UpdateEmissionRate(address indexed user, uint256 _joePerSec);\n\n constructor(\n JoeToken _joe,\n address _devAddr,\n address _treasuryAddr,\n address _investorAddr,\n uint256 _joePerSec,\n uint256 _startTimestamp,\n uint256 _devPercent,\n uint256 _treasuryPercent,\n uint256 _investorPercent\n ) public {\n require(0 <= _devPercent && _devPercent <= 1000, \"constructor: invalid dev percent value\");\n require(0 <= _treasuryPercent && _treasuryPercent <= 1000, \"constructor: invalid treasury percent value\");\n require(0 <= _investorPercent && _investorPercent <= 1000, \"constructor: invalid investor percent value\");\n require(_devPercent + _treasuryPercent + _investorPercent <= 1000, \"constructor: total percent over max\");\n joe = _joe;\n devAddr = _devAddr;\n treasuryAddr = _treasuryAddr;\n investorAddr = _investorAddr;\n joePerSec = _joePerSec;\n startTimestamp = _startTimestamp;\n devPercent = _devPercent;\n treasuryPercent = _treasuryPercent;\n investorPercent = _investorPercent;\n totalAllocPoint = 0;\n }\n\n function poolLength() external view returns (uint256) {\n return poolInfo.length;\n }\n\n // Add a new lp to the pool. Can only be called by the owner.\n // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.\n function add(\n uint256 _allocPoint,\n IERC20 _lpToken,\n IRewarder _rewarder\n ) public onlyOwner {\n require(Address.isContract(address(_lpToken)), \"add: LP token must be a valid contract\");\n require(\n Address.isContract(address(_rewarder)) || address(_rewarder) == address(0),\n \"add: rewarder must be contract or zero\"\n );\n require(!lpTokens.contains(address(_lpToken)), \"add: LP already added\");\n massUpdatePools();\n uint256 lastRewardTimestamp = block.timestamp > startTimestamp ? block.timestamp : startTimestamp;\n totalAllocPoint = totalAllocPoint.add(_allocPoint);\n poolInfo.push(\n PoolInfo({\n lpToken: _lpToken,\n allocPoint: _allocPoint,\n lastRewardTimestamp: lastRewardTimestamp,\n accJoePerShare: 0,\n rewarder: _rewarder\n })\n );\n lpTokens.add(address(_lpToken));\n emit Add(poolInfo.length.sub(1), _allocPoint, _lpToken, _rewarder);\n }\n\n // Update the given pool's JOE allocation point. Can only be called by the owner.\n function set(\n uint256 _pid,\n uint256 _allocPoint,\n IRewarder _rewarder,\n bool overwrite\n ) public onlyOwner {\n require(\n Address.isContract(address(_rewarder)) || address(_rewarder) == address(0),\n \"set: rewarder must be contract or zero\"\n );\n massUpdatePools();\n totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);\n poolInfo[_pid].allocPoint = _allocPoint;\n if (overwrite) {\n poolInfo[_pid].rewarder = _rewarder;\n }\n emit Set(_pid, _allocPoint, overwrite ? _rewarder : poolInfo[_pid].rewarder, overwrite);\n }\n\n // View function to see pending JOEs on frontend.\n function pendingTokens(uint256 _pid, address _user)\n external\n view\n returns (\n uint256 pendingJoe,\n address bonusTokenAddress,\n string memory bonusTokenSymbol,\n uint256 pendingBonusToken\n )\n {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_user];\n uint256 accJoePerShare = pool.accJoePerShare;\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (block.timestamp > pool.lastRewardTimestamp && lpSupply != 0) {\n uint256 multiplier = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 lpPercent = 1000 - devPercent - treasuryPercent - investorPercent;\n uint256 joeReward = multiplier.mul(joePerSec).mul(pool.allocPoint).div(totalAllocPoint).mul(lpPercent).div(\n 1000\n );\n accJoePerShare = accJoePerShare.add(joeReward.mul(1e12).div(lpSupply));\n }\n pendingJoe = user.amount.mul(accJoePerShare).div(1e12).sub(user.rewardDebt);\n\n // If it's a double reward farm, we return info about the bonus token\n if (address(pool.rewarder) != address(0)) {\n (bonusTokenAddress, bonusTokenSymbol) = rewarderBonusTokenInfo(_pid);\n pendingBonusToken = pool.rewarder.pendingTokens(_user);\n }\n }\n\n // Get bonus token info from the rewarder contract for a given pool, if it is a double reward farm\n function rewarderBonusTokenInfo(uint256 _pid)\n public\n view\n returns (address bonusTokenAddress, string memory bonusTokenSymbol)\n {\n PoolInfo storage pool = poolInfo[_pid];\n if (address(pool.rewarder) != address(0)) {\n bonusTokenAddress = address(pool.rewarder.rewardToken());\n bonusTokenSymbol = IERC20(pool.rewarder.rewardToken()).safeSymbol();\n }\n }\n\n // Update reward variables for all pools. Be careful of gas spending!\n function massUpdatePools() public {\n uint256 length = poolInfo.length;\n for (uint256 pid = 0; pid < length; ++pid) {\n updatePool(pid);\n }\n }\n\n // Update reward variables of the given pool to be up-to-date.\n function updatePool(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n if (block.timestamp <= pool.lastRewardTimestamp) {\n return;\n }\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (lpSupply == 0) {\n pool.lastRewardTimestamp = block.timestamp;\n return;\n }\n uint256 multiplier = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 joeReward = multiplier.mul(joePerSec).mul(pool.allocPoint).div(totalAllocPoint);\n uint256 lpPercent = 1000 - devPercent - treasuryPercent - investorPercent;\n joe.mint(devAddr, joeReward.mul(devPercent).div(1000));\n joe.mint(treasuryAddr, joeReward.mul(treasuryPercent).div(1000));\n joe.mint(investorAddr, joeReward.mul(investorPercent).div(1000));\n joe.mint(address(this), joeReward.mul(lpPercent).div(1000));\n pool.accJoePerShare = pool.accJoePerShare.add(joeReward.mul(1e12).div(lpSupply).mul(lpPercent).div(1000));\n pool.lastRewardTimestamp = block.timestamp;\n emit UpdatePool(_pid, pool.lastRewardTimestamp, lpSupply, pool.accJoePerShare);\n }\n\n // Deposit LP tokens to MasterChef for JOE allocation.\n function deposit(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n updatePool(_pid);\n if (user.amount > 0) {\n // Harvest JOE\n uint256 pending = user.amount.mul(pool.accJoePerShare).div(1e12).sub(user.rewardDebt);\n safeJoeTransfer(msg.sender, pending);\n emit Harvest(msg.sender, _pid, pending);\n }\n user.amount = user.amount.add(_amount);\n user.rewardDebt = user.amount.mul(pool.accJoePerShare).div(1e12);\n\n IRewarder rewarder = poolInfo[_pid].rewarder;\n if (address(rewarder) != address(0)) {\n rewarder.onJoeReward(msg.sender, user.amount);\n }\n\n pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);\n emit Deposit(msg.sender, _pid, _amount);\n }\n\n // Withdraw LP tokens from MasterChef.\n function withdraw(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n require(user.amount >= _amount, \"withdraw: not good\");\n\n updatePool(_pid);\n\n // Harvest JOE\n uint256 pending = user.amount.mul(pool.accJoePerShare).div(1e12).sub(user.rewardDebt);\n safeJoeTransfer(msg.sender, pending);\n emit Harvest(msg.sender, _pid, pending);\n\n user.amount = user.amount.sub(_amount);\n user.rewardDebt = user.amount.mul(pool.accJoePerShare).div(1e12);\n\n IRewarder rewarder = poolInfo[_pid].rewarder;\n if (address(rewarder) != address(0)) {\n rewarder.onJoeReward(msg.sender, user.amount);\n }\n\n pool.lpToken.safeTransfer(address(msg.sender), _amount);\n emit Withdraw(msg.sender, _pid, _amount);\n }\n\n // Withdraw without caring about rewards. EMERGENCY ONLY.\n function emergencyWithdraw(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n pool.lpToken.safeTransfer(address(msg.sender), user.amount);\n emit EmergencyWithdraw(msg.sender, _pid, user.amount);\n user.amount = 0;\n user.rewardDebt = 0;\n }\n\n // Safe joe transfer function, just in case if rounding error causes pool to not have enough JOEs.\n function safeJoeTransfer(address _to, uint256 _amount) internal {\n uint256 joeBal = joe.balanceOf(address(this));\n if (_amount > joeBal) {\n joe.transfer(_to, joeBal);\n } else {\n joe.transfer(_to, _amount);\n }\n }\n\n // Update dev address by the previous dev.\n function dev(address _devAddr) public {\n require(msg.sender == devAddr, \"dev: wut?\");\n devAddr = _devAddr;\n emit SetDevAddress(msg.sender, _devAddr);\n }\n\n function setDevPercent(uint256 _newDevPercent) public onlyOwner {\n require(0 <= _newDevPercent && _newDevPercent <= 1000, \"setDevPercent: invalid percent value\");\n require(treasuryPercent + _newDevPercent + investorPercent <= 1000, \"setDevPercent: total percent over max\");\n devPercent = _newDevPercent;\n }\n\n // Update treasury address by the previous treasury.\n function setTreasuryAddr(address _treasuryAddr) public {\n require(msg.sender == treasuryAddr, \"setTreasuryAddr: wut?\");\n treasuryAddr = _treasuryAddr;\n }\n\n function setTreasuryPercent(uint256 _newTreasuryPercent) public onlyOwner {\n require(0 <= _newTreasuryPercent && _newTreasuryPercent <= 1000, \"setTreasuryPercent: invalid percent value\");\n require(\n devPercent + _newTreasuryPercent + investorPercent <= 1000,\n \"setTreasuryPercent: total percent over max\"\n );\n treasuryPercent = _newTreasuryPercent;\n }\n\n // Update the investor address by the previous investor.\n function setInvestorAddr(address _investorAddr) public {\n require(msg.sender == investorAddr, \"setInvestorAddr: wut?\");\n investorAddr = _investorAddr;\n }\n\n function setInvestorPercent(uint256 _newInvestorPercent) public onlyOwner {\n require(0 <= _newInvestorPercent && _newInvestorPercent <= 1000, \"setInvestorPercent: invalid percent value\");\n require(\n devPercent + _newInvestorPercent + treasuryPercent <= 1000,\n \"setInvestorPercent: total percent over max\"\n );\n investorPercent = _newInvestorPercent;\n }\n\n // Pancake has to add hidden dummy pools inorder to alter the emission,\n // here we make it simple and transparent to all.\n function updateEmissionRate(uint256 _joePerSec) public onlyOwner {\n massUpdatePools();\n joePerSec = _joePerSec;\n emit UpdateEmissionRate(msg.sender, _joePerSec);\n }\n}\n" + }, + "contracts/libraries/BoringERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\n// solhint-disable avoid-low-level-calls\n\nlibrary BoringERC20 {\n bytes4 private constant SIG_SYMBOL = 0x95d89b41; // symbol()\n bytes4 private constant SIG_NAME = 0x06fdde03; // name()\n bytes4 private constant SIG_DECIMALS = 0x313ce567; // decimals()\n bytes4 private constant SIG_TRANSFER = 0xa9059cbb; // transfer(address,uint256)\n bytes4 private constant SIG_TRANSFER_FROM = 0x23b872dd; // transferFrom(address,address,uint256)\n\n function returnDataToString(bytes memory data) internal pure returns (string memory) {\n if (data.length >= 64) {\n return abi.decode(data, (string));\n } else if (data.length == 32) {\n uint8 i = 0;\n while (i < 32 && data[i] != 0) {\n i++;\n }\n bytes memory bytesArray = new bytes(i);\n for (i = 0; i < 32 && data[i] != 0; i++) {\n bytesArray[i] = data[i];\n }\n return string(bytesArray);\n } else {\n return \"???\";\n }\n }\n\n /// @notice Provides a safe ERC20.symbol version which returns '???' as fallback string.\n /// @param token The address of the ERC-20 token contract.\n /// @return (string) Token symbol.\n function safeSymbol(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_SYMBOL));\n return success ? returnDataToString(data) : \"???\";\n }\n\n /// @notice Provides a safe ERC20.name version which returns '???' as fallback string.\n /// @param token The address of the ERC-20 token contract.\n /// @return (string) Token name.\n function safeName(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_NAME));\n return success ? returnDataToString(data) : \"???\";\n }\n\n /// @notice Provides a safe ERC20.decimals version which returns '18' as fallback value.\n /// @param token The address of the ERC-20 token contract.\n /// @return (uint8) Token decimals.\n function safeDecimals(IERC20 token) internal view returns (uint8) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_DECIMALS));\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\n }\n\n /// @notice Provides a safe ERC20.transfer version for different ERC-20 implementations.\n /// Reverts on a failed transfer.\n /// @param token The address of the ERC-20 token.\n /// @param to Transfer tokens to.\n /// @param amount The token amount.\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(SIG_TRANSFER, to, amount));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"BoringERC20: Transfer failed\");\n }\n\n /// @notice Provides a safe ERC20.transferFrom version for different ERC-20 implementations.\n /// Reverts on a failed transfer.\n /// @param token The address of the ERC-20 token.\n /// @param from Transfer tokens from.\n /// @param to Transfer tokens to.\n /// @param amount The token amount.\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(\n abi.encodeWithSelector(SIG_TRANSFER_FROM, from, to, amount)\n );\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"BoringERC20: TransferFrom failed\");\n }\n}\n" + }, + "contracts/sushi/MasterChef.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/utils/EnumerableSet.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./SushiToken.sol\";\n\n// MasterChef is the master of Sushi. He can make Sushi and he is a fair guy.\n//\n// Note that it's ownable and the owner wields tremendous power. The ownership\n// will be transferred to a governance smart contract once SUSHI is sufficiently\n// distributed and the community can show to govern itself.\n//\n// Have fun reading it. Hopefully it's bug-free. God bless.\ncontract MasterChef is Ownable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n // Info of each user.\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n //\n // We do some fancy math here. Basically, any point in time, the amount of SUSHIs\n // entitled to a user but is pending to be distributed is:\n //\n // pending reward = (user.amount * pool.accSushiPerShare) - user.rewardDebt\n //\n // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:\n // 1. The pool's `accSushiPerShare` (and `lastRewardBlock`) gets updated.\n // 2. User receives the pending reward sent to his/her address.\n // 3. User's `amount` gets updated.\n // 4. User's `rewardDebt` gets updated.\n }\n // Info of each pool.\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. SUSHIs to distribute per block.\n uint256 lastRewardBlock; // Last block number that SUSHIs distribution occurs.\n uint256 accSushiPerShare; // Accumulated SUSHIs per share, times 1e12. See below.\n }\n // The SUSHI TOKEN!\n SushiToken public sushi;\n // Dev address.\n address public devaddr;\n // Block number when bonus SUSHI period ends.\n uint256 public bonusEndBlock;\n // SUSHI tokens created per block.\n uint256 public sushiPerBlock;\n // Bonus muliplier for early sushi makers.\n uint256 public constant BONUS_MULTIPLIER = 1;\n // Info of each pool.\n PoolInfo[] public poolInfo;\n // Info of each user that stakes LP tokens.\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n // Total allocation poitns. Must be the sum of all allocation points in all pools.\n uint256 public totalAllocPoint = 0;\n // The block number when SUSHI mining starts.\n uint256 public startBlock;\n event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\n event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\n\n constructor(\n SushiToken _sushi,\n address _devaddr,\n uint256 _sushiPerBlock,\n uint256 _startBlock,\n uint256 _bonusEndBlock\n ) public {\n sushi = _sushi;\n devaddr = _devaddr;\n sushiPerBlock = _sushiPerBlock;\n bonusEndBlock = _bonusEndBlock;\n startBlock = _startBlock;\n }\n\n function poolLength() external view returns (uint256) {\n return poolInfo.length;\n }\n\n // Add a new lp to the pool. Can only be called by the owner.\n // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.\n function add(\n uint256 _allocPoint,\n IERC20 _lpToken,\n bool _withUpdate\n ) public onlyOwner {\n if (_withUpdate) {\n massUpdatePools();\n }\n uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;\n totalAllocPoint = totalAllocPoint.add(_allocPoint);\n poolInfo.push(\n PoolInfo({\n lpToken: _lpToken,\n allocPoint: _allocPoint,\n lastRewardBlock: lastRewardBlock,\n accSushiPerShare: 0\n })\n );\n }\n\n // Update the given pool's SUSHI allocation point. Can only be called by the owner.\n function set(\n uint256 _pid,\n uint256 _allocPoint,\n bool _withUpdate\n ) public onlyOwner {\n if (_withUpdate) {\n massUpdatePools();\n }\n totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);\n poolInfo[_pid].allocPoint = _allocPoint;\n }\n\n // Return reward multiplier over the given _from to _to block.\n function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) {\n if (_to <= bonusEndBlock) {\n return _to.sub(_from).mul(BONUS_MULTIPLIER);\n } else if (_from >= bonusEndBlock) {\n return _to.sub(_from);\n } else {\n return bonusEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(_to.sub(bonusEndBlock));\n }\n }\n\n // View function to see pending SUSHIs on frontend.\n function pendingSushi(uint256 _pid, address _user) external view returns (uint256) {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_user];\n uint256 accSushiPerShare = pool.accSushiPerShare;\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (block.number > pool.lastRewardBlock && lpSupply != 0) {\n uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number);\n uint256 sushiReward = multiplier.mul(sushiPerBlock).mul(pool.allocPoint).div(totalAllocPoint);\n accSushiPerShare = accSushiPerShare.add(sushiReward.mul(1e12).div(lpSupply));\n }\n return user.amount.mul(accSushiPerShare).div(1e12).sub(user.rewardDebt);\n }\n\n // Update reward vairables for all pools. Be careful of gas spending!\n function massUpdatePools() public {\n uint256 length = poolInfo.length;\n for (uint256 pid = 0; pid < length; ++pid) {\n updatePool(pid);\n }\n }\n\n // Update reward variables of the given pool to be up-to-date.\n function updatePool(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n if (block.number <= pool.lastRewardBlock) {\n return;\n }\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (lpSupply == 0) {\n pool.lastRewardBlock = block.number;\n return;\n }\n uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number);\n uint256 sushiReward = multiplier.mul(sushiPerBlock).mul(pool.allocPoint).div(totalAllocPoint);\n sushi.mint(devaddr, sushiReward.div(10));\n sushi.mint(address(this), sushiReward);\n pool.accSushiPerShare = pool.accSushiPerShare.add(sushiReward.mul(1e12).div(lpSupply));\n pool.lastRewardBlock = block.number;\n }\n\n // Deposit LP tokens to MasterChef for SUSHI allocation.\n function deposit(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n updatePool(_pid);\n if (user.amount > 0) {\n uint256 pending = user.amount.mul(pool.accSushiPerShare).div(1e12).sub(user.rewardDebt);\n safeSushiTransfer(msg.sender, pending);\n }\n pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);\n user.amount = user.amount.add(_amount);\n user.rewardDebt = user.amount.mul(pool.accSushiPerShare).div(1e12);\n emit Deposit(msg.sender, _pid, _amount);\n }\n\n // Withdraw LP tokens from MasterChef.\n function withdraw(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n require(user.amount >= _amount, \"withdraw: not good\");\n updatePool(_pid);\n uint256 pending = user.amount.mul(pool.accSushiPerShare).div(1e12).sub(user.rewardDebt);\n safeSushiTransfer(msg.sender, pending);\n user.amount = user.amount.sub(_amount);\n user.rewardDebt = user.amount.mul(pool.accSushiPerShare).div(1e12);\n pool.lpToken.safeTransfer(address(msg.sender), _amount);\n emit Withdraw(msg.sender, _pid, _amount);\n }\n\n // Withdraw without caring about rewards. EMERGENCY ONLY.\n function emergencyWithdraw(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n pool.lpToken.safeTransfer(address(msg.sender), user.amount);\n emit EmergencyWithdraw(msg.sender, _pid, user.amount);\n user.amount = 0;\n user.rewardDebt = 0;\n }\n\n // Safe sushi transfer function, just in case if rounding error causes pool to not have enough SUSHIs.\n function safeSushiTransfer(address _to, uint256 _amount) internal {\n uint256 sushiBal = sushi.balanceOf(address(this));\n if (_amount > sushiBal) {\n sushi.transfer(_to, sushiBal);\n } else {\n sushi.transfer(_to, _amount);\n }\n }\n\n // Update dev address by the previous dev.\n function dev(address _devaddr) public {\n require(msg.sender == devaddr, \"dev: wut?\");\n devaddr = _devaddr;\n }\n}\n" + }, + "contracts/timelock/Timelock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// COPIED FROM https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/GovernorAlpha.sol\n// Copyright 2020 Compound Labs, Inc.\n// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Ctrl+f for XXX to see all the modifications.\n\n// XXX: pragma solidity ^0.5.16;\npragma solidity 0.6.12;\n\n// XXX: import \"./SafeMath.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\n\ncontract Timelock {\n using SafeMath for uint256;\n\n event NewAdmin(address indexed newAdmin);\n event NewPendingAdmin(address indexed newPendingAdmin);\n event NewDelay(uint256 indexed newDelay);\n event CancelTransaction(\n bytes32 indexed txHash,\n address indexed target,\n uint256 value,\n string signature,\n bytes data,\n uint256 eta\n );\n event ExecuteTransaction(\n bytes32 indexed txHash,\n address indexed target,\n uint256 value,\n string signature,\n bytes data,\n uint256 eta\n );\n event QueueTransaction(\n bytes32 indexed txHash,\n address indexed target,\n uint256 value,\n string signature,\n bytes data,\n uint256 eta\n );\n\n uint256 public constant GRACE_PERIOD = 14 days;\n uint256 public constant MINIMUM_DELAY = 12 hours;\n uint256 public constant MAXIMUM_DELAY = 30 days;\n\n address public admin;\n address public pendingAdmin;\n uint256 public delay;\n bool public admin_initialized;\n\n mapping(bytes32 => bool) public queuedTransactions;\n\n constructor(address admin_, uint256 delay_) public {\n require(delay_ >= MINIMUM_DELAY, \"Timelock::constructor: Delay must exceed minimum delay.\");\n require(delay_ <= MAXIMUM_DELAY, \"Timelock::constructor: Delay must not exceed maximum delay.\");\n\n admin = admin_;\n delay = delay_;\n admin_initialized = false;\n }\n\n // XXX: function() external payable { }\n receive() external payable {}\n\n function setDelay(uint256 delay_) public {\n require(msg.sender == address(this), \"Timelock::setDelay: Call must come from Timelock.\");\n require(delay_ >= MINIMUM_DELAY, \"Timelock::setDelay: Delay must exceed minimum delay.\");\n require(delay_ <= MAXIMUM_DELAY, \"Timelock::setDelay: Delay must not exceed maximum delay.\");\n delay = delay_;\n\n emit NewDelay(delay);\n }\n\n function acceptAdmin() public {\n require(msg.sender == pendingAdmin, \"Timelock::acceptAdmin: Call must come from pendingAdmin.\");\n admin = msg.sender;\n pendingAdmin = address(0);\n\n emit NewAdmin(admin);\n }\n\n function setPendingAdmin(address pendingAdmin_) public {\n // allows one time setting of admin for deployment purposes\n if (admin_initialized) {\n require(msg.sender == address(this), \"Timelock::setPendingAdmin: Call must come from Timelock.\");\n } else {\n require(msg.sender == admin, \"Timelock::setPendingAdmin: First call must come from admin.\");\n admin_initialized = true;\n }\n pendingAdmin = pendingAdmin_;\n\n emit NewPendingAdmin(pendingAdmin);\n }\n\n function queueTransaction(\n address target,\n uint256 value,\n string memory signature,\n bytes memory data,\n uint256 eta\n ) public returns (bytes32) {\n require(msg.sender == admin, \"Timelock::queueTransaction: Call must come from admin.\");\n require(\n eta >= getBlockTimestamp().add(delay),\n \"Timelock::queueTransaction: Estimated execution block must satisfy delay.\"\n );\n\n bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));\n queuedTransactions[txHash] = true;\n\n emit QueueTransaction(txHash, target, value, signature, data, eta);\n return txHash;\n }\n\n function cancelTransaction(\n address target,\n uint256 value,\n string memory signature,\n bytes memory data,\n uint256 eta\n ) public {\n require(msg.sender == admin, \"Timelock::cancelTransaction: Call must come from admin.\");\n\n bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));\n queuedTransactions[txHash] = false;\n\n emit CancelTransaction(txHash, target, value, signature, data, eta);\n }\n\n function executeTransaction(\n address target,\n uint256 value,\n string memory signature,\n bytes memory data,\n uint256 eta\n ) public payable returns (bytes memory) {\n require(msg.sender == admin, \"Timelock::executeTransaction: Call must come from admin.\");\n\n bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));\n require(queuedTransactions[txHash], \"Timelock::executeTransaction: Transaction hasn't been queued.\");\n require(getBlockTimestamp() >= eta, \"Timelock::executeTransaction: Transaction hasn't surpassed time lock.\");\n require(getBlockTimestamp() <= eta.add(GRACE_PERIOD), \"Timelock::executeTransaction: Transaction is stale.\");\n\n queuedTransactions[txHash] = false;\n\n bytes memory callData;\n\n if (bytes(signature).length == 0) {\n callData = data;\n } else {\n callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data);\n }\n\n // solium-disable-next-line security/no-call-value\n (bool success, bytes memory returnData) = target.call.value(value)(callData);\n require(success, \"Timelock::executeTransaction: Transaction execution reverted.\");\n\n emit ExecuteTransaction(txHash, target, value, signature, data, eta);\n\n return returnData;\n }\n\n function getBlockTimestamp() internal view returns (uint256) {\n // solium-disable-next-line security/no-block-members\n return block.timestamp;\n }\n}\n" + }, + "contracts/timelock/CustomMasterChefJoeV2Timelock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// COPIED FROM https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/GovernorAlpha.sol\n// Copyright 2020 Compound Labs, Inc.\n// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\n// Ctrl+f for XXX to see all the modifications.\n\n// XXX: pragma solidity ^0.5.16;\npragma solidity 0.6.12;\n\n// XXX: import \"./SafeMath.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\n\ncontract CustomMasterChefJoeV2Timelock {\n using SafeMath for uint256;\n\n event NewAdmin(address indexed newAdmin);\n event NewPendingAdmin(address indexed newPendingAdmin);\n event NewDelay(uint256 indexed newDelay);\n event CancelTransaction(\n bytes32 indexed txHash,\n address indexed target,\n uint256 value,\n string signature,\n bytes data,\n uint256 eta\n );\n event ExecuteTransaction(\n bytes32 indexed txHash,\n address indexed target,\n uint256 value,\n string signature,\n bytes data,\n uint256 eta\n );\n event QueueTransaction(\n bytes32 indexed txHash,\n address indexed target,\n uint256 value,\n string signature,\n bytes data,\n uint256 eta\n );\n\n uint256 public constant GRACE_PERIOD = 14 days;\n uint256 public constant MINIMUM_DELAY = 12 hours;\n uint256 public constant MAXIMUM_DELAY = 30 days;\n\n string private constant SET_DEV_PERCENT_SIG = \"setDevPercent(uint256)\";\n string private constant SET_TREASURY_PERCENT_SIG = \"setTreasuryPercent(uint256)\";\n string private constant SET_INVESTOR_PERCENT_SIG = \"setInvestorPercent(uint256)\";\n string private constant UPDATE_EMISSION_RATE_SIG = \"updateEmissionRate(uint256)\";\n\n address public admin;\n address public pendingAdmin;\n uint256 public delay;\n uint256 public devPercentLimit;\n uint256 public investorPercentLimit;\n uint256 public treasuryPercentLimit;\n uint256 public joePerSecLimit;\n bool public admin_initialized;\n\n mapping(bytes32 => bool) public queuedTransactions;\n\n modifier withinLimits(string memory signature, bytes memory data) {\n if (keccak256(bytes(signature)) == keccak256(bytes(SET_DEV_PERCENT_SIG))) {\n uint256 devPercent = abi.decode(data, (uint256));\n require(\n devPercent <= devPercentLimit,\n \"CustomMasterChefJoeV2Timelock::withinLimits: devPercent must not exceed limit.\"\n );\n } else if (keccak256(bytes(signature)) == keccak256(bytes(SET_TREASURY_PERCENT_SIG))) {\n uint256 treasuryPercent = abi.decode(data, (uint256));\n require(\n treasuryPercent <= treasuryPercentLimit,\n \"CustomMasterChefJoeV2Timelock::withinLimits: treasuryPercent must not exceed limit.\"\n );\n } else if (keccak256(bytes(signature)) == keccak256(bytes(SET_INVESTOR_PERCENT_SIG))) {\n uint256 investorPercent = abi.decode(data, (uint256));\n require(\n investorPercent <= investorPercentLimit,\n \"CustomMasterChefJoeV2Timelock::withinLimits: investorPercent must not exceed limit.\"\n );\n } else if (keccak256(bytes(signature)) == keccak256(bytes(UPDATE_EMISSION_RATE_SIG))) {\n uint256 joePerSec = abi.decode(data, (uint256));\n require(\n joePerSec <= joePerSecLimit,\n \"CustomMasterChefJoeV2Timelock::withinLimits: joePerSec must not exceed limit.\"\n );\n }\n _;\n }\n\n constructor(\n address admin_,\n uint256 delay_,\n uint256 devPercentLimit_,\n uint256 treasuryPercentLimit_,\n uint256 investorPercentLimit_,\n uint256 joePerSecLimit_\n ) public {\n require(\n delay_ >= MINIMUM_DELAY,\n \"CustomMasterChefJoeV2Timelock::constructor: Delay must exceed minimum delay.\"\n );\n require(\n delay_ <= MAXIMUM_DELAY,\n \"CustomMasterChefJoeV2Timelock::constructor: Delay must not exceed maximum delay.\"\n );\n\n admin = admin_;\n delay = delay_;\n admin_initialized = false;\n devPercentLimit = devPercentLimit_;\n treasuryPercentLimit = treasuryPercentLimit_;\n investorPercentLimit = investorPercentLimit_;\n joePerSecLimit = joePerSecLimit_;\n }\n\n // XXX: function() external payable { }\n receive() external payable {}\n\n function setDelay(uint256 delay_) public {\n require(\n msg.sender == address(this),\n \"CustomMasterChefJoeV2Timelock::setDelay: Call must come from CustomMasterChefJoeV2Timelock.\"\n );\n require(delay_ >= MINIMUM_DELAY, \"CustomMasterChefJoeV2Timelock::setDelay: Delay must exceed minimum delay.\");\n require(\n delay_ <= MAXIMUM_DELAY,\n \"CustomMasterChefJoeV2Timelock::setDelay: Delay must not exceed maximum delay.\"\n );\n delay = delay_;\n\n emit NewDelay(delay);\n }\n\n function acceptAdmin() public {\n require(\n msg.sender == pendingAdmin,\n \"CustomMasterChefJoeV2Timelock::acceptAdmin: Call must come from pendingAdmin.\"\n );\n admin = msg.sender;\n pendingAdmin = address(0);\n\n emit NewAdmin(admin);\n }\n\n function setPendingAdmin(address pendingAdmin_) public {\n // allows one time setting of admin for deployment purposes\n if (admin_initialized) {\n require(\n msg.sender == address(this),\n \"CustomMasterChefJoeV2Timelock::setPendingAdmin: Call must come from CustomMasterChefJoeV2Timelock.\"\n );\n } else {\n require(\n msg.sender == admin,\n \"CustomMasterChefJoeV2Timelock::setPendingAdmin: First call must come from admin.\"\n );\n admin_initialized = true;\n }\n pendingAdmin = pendingAdmin_;\n\n emit NewPendingAdmin(pendingAdmin);\n }\n\n function queueTransaction(\n address target,\n uint256 value,\n string memory signature,\n bytes memory data,\n uint256 eta\n ) public withinLimits(signature, data) returns (bytes32) {\n require(msg.sender == admin, \"CustomMasterChefJoeV2Timelock::queueTransaction: Call must come from admin.\");\n require(\n eta >= getBlockTimestamp().add(delay),\n \"CustomMasterChefJoeV2Timelock::queueTransaction: Estimated execution block must satisfy delay.\"\n );\n\n bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));\n queuedTransactions[txHash] = true;\n\n emit QueueTransaction(txHash, target, value, signature, data, eta);\n return txHash;\n }\n\n function cancelTransaction(\n address target,\n uint256 value,\n string memory signature,\n bytes memory data,\n uint256 eta\n ) public {\n require(msg.sender == admin, \"CustomMasterChefJoeV2Timelock::cancelTransaction: Call must come from admin.\");\n\n bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));\n queuedTransactions[txHash] = false;\n\n emit CancelTransaction(txHash, target, value, signature, data, eta);\n }\n\n function executeTransaction(\n address target,\n uint256 value,\n string memory signature,\n bytes memory data,\n uint256 eta\n ) public payable returns (bytes memory) {\n require(msg.sender == admin, \"CustomMasterChefJoeV2Timelock::executeTransaction: Call must come from admin.\");\n\n bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));\n require(\n queuedTransactions[txHash],\n \"CustomMasterChefJoeV2Timelock::executeTransaction: Transaction hasn't been queued.\"\n );\n require(\n getBlockTimestamp() >= eta,\n \"CustomMasterChefJoeV2Timelock::executeTransaction: Transaction hasn't surpassed time lock.\"\n );\n require(\n getBlockTimestamp() <= eta.add(GRACE_PERIOD),\n \"CustomMasterChefJoeV2Timelock::executeTransaction: Transaction is stale.\"\n );\n\n queuedTransactions[txHash] = false;\n\n bytes memory callData;\n\n callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data);\n\n // solium-disable-next-line security/no-call-value\n (bool success, bytes memory returnData) = target.call.value(value)(callData);\n require(success, \"CustomMasterChefJoeV2Timelock::executeTransaction: Transaction execution reverted.\");\n\n emit ExecuteTransaction(txHash, target, value, signature, data, eta);\n\n return returnData;\n }\n\n function getBlockTimestamp() internal view returns (uint256) {\n // solium-disable-next-line security/no-block-members\n return block.timestamp;\n }\n}\n" + }, + "contracts/rewarders/SimpleRewarderPerSec.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\nimport \"../boringcrypto/BoringOwnable.sol\";\nimport \"../libraries/SafeERC20.sol\";\n\ninterface IRewarder {\n using SafeERC20 for IERC20;\n\n function onJoeReward(address user, uint256 newLpAmount) external;\n\n function pendingTokens(address user) external view returns (uint256 pending);\n\n function rewardToken() external view returns (IERC20);\n}\n\ninterface IMasterChefJoe {\n using SafeERC20 for IERC20;\n\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this poolInfo. SUSHI to distribute per block.\n uint256 lastRewardTimestamp; // Last block timestamp that SUSHI distribution occurs.\n uint256 accJoePerShare; // Accumulated SUSHI per share, times 1e12. See below.\n }\n\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n}\n\n/**\n * This is a sample contract to be used in the MasterChefJoe contract for partners to reward\n * stakers with their native token alongside JOE.\n *\n * It assumes no minting rights, so requires a set amount of YOUR_TOKEN to be transferred to this contract prior.\n * E.g. say you've allocated 100,000 XYZ to the JOE-XYZ farm over 30 days. Then you would need to transfer\n * 100,000 XYZ and set the block reward accordingly so it's fully distributed after 30 days.\n *\n *\n * Issue with the previous version is that this fraction, `tokenReward.mul(ACC_TOKEN_PRECISION).div(lpSupply)`,\n * can return 0 or be very inacurate with some tokens:\n * uint256 timeElapsed = block.timestamp.sub(pool.lastRewardTimestamp);\n * uint256 tokenReward = timeElapsed.mul(tokenPerSec);\n * accTokenPerShare = accTokenPerShare.add(\n * tokenReward.mul(ACC_TOKEN_PRECISION).div(lpSupply)\n * );\n * The goal is to set ACC_TOKEN_PRECISION high enough to prevent this without causing overflow too.\n */\ncontract SimpleRewarderPerSec is IRewarder, BoringOwnable, ReentrancyGuard {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n IERC20 public immutable override rewardToken;\n IERC20 public immutable lpToken;\n bool public immutable isNative;\n IMasterChefJoe public immutable MCJ;\n\n /// @notice Info of each MCJ user.\n /// `amount` LP token amount the user has provided.\n /// `rewardDebt` The amount of YOUR_TOKEN entitled to the user.\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n uint256 unpaidRewards;\n }\n\n /// @notice Info of each MCJ poolInfo.\n /// `accTokenPerShare` Amount of YOUR_TOKEN each LP token is worth.\n /// `lastRewardTimestamp` The last timestamp YOUR_TOKEN was rewarded to the poolInfo.\n struct PoolInfo {\n uint256 accTokenPerShare;\n uint256 lastRewardTimestamp;\n }\n\n /// @notice Info of the poolInfo.\n PoolInfo public poolInfo;\n /// @notice Info of each user that stakes LP tokens.\n mapping(address => UserInfo) public userInfo;\n\n uint256 public tokenPerSec;\n\n uint256 private ACC_TOKEN_PRECISION;\n\n event OnReward(address indexed user, uint256 amount);\n event RewardRateUpdated(uint256 oldRate, uint256 newRate);\n\n modifier onlyMCJ() {\n require(msg.sender == address(MCJ), \"onlyMCJ: only MasterChefJoe can call this function\");\n _;\n }\n\n constructor(\n IERC20 _rewardToken,\n IERC20 _lpToken,\n uint256 _tokenPerSec,\n IMasterChefJoe _MCJ,\n bool _isNative\n ) public {\n require(Address.isContract(address(_rewardToken)), \"constructor: reward token must be a valid contract\");\n require(Address.isContract(address(_lpToken)), \"constructor: LP token must be a valid contract\");\n require(Address.isContract(address(_MCJ)), \"constructor: MasterChefJoe must be a valid contract\");\n require(_tokenPerSec <= 1e30, \"constructor: token per seconds can't be greater than 1e30\");\n\n rewardToken = _rewardToken;\n lpToken = _lpToken;\n tokenPerSec = _tokenPerSec;\n MCJ = _MCJ;\n isNative = _isNative;\n poolInfo = PoolInfo({lastRewardTimestamp: block.timestamp, accTokenPerShare: 0});\n\n // Given the fraction, tokenReward * ACC_TOKEN_PRECISION / lpSupply, we consider\n // several edge cases.\n\n // Edge case n1: maximize the numerator, minimize the denominator.\n // `lpSupply` = 1 WEI\n // `tokenPerSec` = 1e(30)\n // `timeElapsed` = 31 years, i.e. 1e9 seconds\n // result = 1e9 * 1e30 * 1e36 / 1\n // = 1e75\n // (No overflow as max uint256 is 1.15e77).\n // PS: This will overflow when `timeElapsed` becomes greater than 1e11, i.e. in more than 3_000 years\n // so it should be fine.\n //\n // Edge case n2: minimize the numerator, maximize the denominator.\n // `lpSupply` = max(uint112) = 1e34\n // `tokenPerSec` = 1 WEI\n // `timeElapsed` = 1 second\n // result = 1 * 1 * 1e36 / 1e34\n // = 1e2\n // (Not rounded to zero, therefore ACC_TOKEN_PRECISION = 1e36 is safe)\n ACC_TOKEN_PRECISION = 1e36;\n }\n\n /// @notice Update reward variables of the given poolInfo.\n /// @return pool Returns the pool that was updated.\n function updatePool() public returns (PoolInfo memory pool) {\n pool = poolInfo;\n\n if (block.timestamp > pool.lastRewardTimestamp) {\n uint256 lpSupply = lpToken.balanceOf(address(MCJ));\n\n if (lpSupply > 0) {\n uint256 timeElapsed = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 tokenReward = timeElapsed.mul(tokenPerSec);\n pool.accTokenPerShare = pool.accTokenPerShare.add((tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply));\n }\n\n pool.lastRewardTimestamp = block.timestamp;\n poolInfo = pool;\n }\n }\n\n /// @notice Sets the distribution reward rate. This will also update the poolInfo.\n /// @param _tokenPerSec The number of tokens to distribute per second\n function setRewardRate(uint256 _tokenPerSec) external onlyOwner {\n updatePool();\n\n uint256 oldRate = tokenPerSec;\n tokenPerSec = _tokenPerSec;\n\n emit RewardRateUpdated(oldRate, _tokenPerSec);\n }\n\n /// @notice Function called by MasterChefJoe whenever staker claims JOE harvest. Allows staker to also receive a 2nd reward token.\n /// @param _user Address of user\n /// @param _lpAmount Number of LP tokens the user has\n function onJoeReward(address _user, uint256 _lpAmount) external override onlyMCJ nonReentrant {\n updatePool();\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n uint256 pending;\n if (user.amount > 0) {\n pending = (user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt).add(\n user.unpaidRewards\n );\n\n if (isNative) {\n uint256 balance = address(this).balance;\n if (pending > balance) {\n (bool success, ) = _user.call.value(balance)(\"\");\n require(success, \"Transfer failed\");\n user.unpaidRewards = pending - balance;\n } else {\n (bool success, ) = _user.call.value(pending)(\"\");\n require(success, \"Transfer failed\");\n user.unpaidRewards = 0;\n }\n } else {\n uint256 balance = rewardToken.balanceOf(address(this));\n if (pending > balance) {\n rewardToken.safeTransfer(_user, balance);\n user.unpaidRewards = pending - balance;\n } else {\n rewardToken.safeTransfer(_user, pending);\n user.unpaidRewards = 0;\n }\n }\n }\n\n user.amount = _lpAmount;\n user.rewardDebt = user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION;\n emit OnReward(_user, pending - user.unpaidRewards);\n }\n\n /// @notice View function to see pending tokens\n /// @param _user Address of user.\n /// @return pending reward for a given user.\n function pendingTokens(address _user) external view override returns (uint256 pending) {\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n\n uint256 accTokenPerShare = pool.accTokenPerShare;\n uint256 lpSupply = lpToken.balanceOf(address(MCJ));\n\n if (block.timestamp > pool.lastRewardTimestamp && lpSupply != 0) {\n uint256 timeElapsed = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 tokenReward = timeElapsed.mul(tokenPerSec);\n accTokenPerShare = accTokenPerShare.add(tokenReward.mul(ACC_TOKEN_PRECISION).div(lpSupply));\n }\n\n pending = (user.amount.mul(accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt).add(\n user.unpaidRewards\n );\n }\n\n /// @notice In case rewarder is stopped before emissions finished, this function allows\n /// withdrawal of remaining tokens.\n function emergencyWithdraw() public onlyOwner {\n if (isNative) {\n (bool success, ) = msg.sender.call.value(address(this).balance)(\"\");\n require(success, \"Transfer failed\");\n } else {\n rewardToken.safeTransfer(address(msg.sender), rewardToken.balanceOf(address(this)));\n }\n }\n\n /// @notice View function to see balance of reward token.\n function balance() external view returns (uint256) {\n if (isNative) {\n return address(this).balance;\n } else {\n return rewardToken.balanceOf(address(this));\n }\n }\n\n /// @notice payable function needed to receive AVAX\n receive() external payable {}\n}\n" + }, + "@openzeppelin/contracts/utils/ReentrancyGuard.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n constructor () internal {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and make it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n}\n" + }, + "contracts/boringcrypto/BoringOwnable.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\n// Audit on 5-Jan-2021 by Keno and BoringCrypto\n// Source: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol + Claimable.sol\n// Edited by BoringCrypto\n\ncontract BoringOwnableData {\n address public owner;\n address public pendingOwner;\n}\n\ncontract BoringOwnable is BoringOwnableData {\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /// @notice `owner` defaults to msg.sender on construction.\n constructor() public {\n owner = msg.sender;\n emit OwnershipTransferred(address(0), msg.sender);\n }\n\n /// @notice Transfers ownership to `newOwner`. Either directly or claimable by the new pending owner.\n /// Can only be invoked by the current `owner`.\n /// @param newOwner Address of the new owner.\n /// @param direct True if `newOwner` should be set immediately. False if `newOwner` needs to use `claimOwnership`.\n /// @param renounce Allows the `newOwner` to be `address(0)` if `direct` and `renounce` is True. Has no effect otherwise.\n function transferOwnership(\n address newOwner,\n bool direct,\n bool renounce\n ) public onlyOwner {\n if (direct) {\n // Checks\n require(newOwner != address(0) || renounce, \"Ownable: zero address\");\n\n // Effects\n emit OwnershipTransferred(owner, newOwner);\n owner = newOwner;\n pendingOwner = address(0);\n } else {\n // Effects\n pendingOwner = newOwner;\n }\n }\n\n /// @notice Needs to be called by `pendingOwner` to claim ownership.\n function claimOwnership() public {\n address _pendingOwner = pendingOwner;\n\n // Checks\n require(msg.sender == _pendingOwner, \"Ownable: caller != pending owner\");\n\n // Effects\n emit OwnershipTransferred(owner, _pendingOwner);\n owner = _pendingOwner;\n pendingOwner = address(0);\n }\n\n /// @notice Only allows the `owner` to execute the function.\n modifier onlyOwner() {\n require(msg.sender == owner, \"Ownable: caller is not the owner\");\n _;\n }\n}\n" + }, + "contracts/traderjoe/FarmLensV2.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\nimport \"../libraries/SafeMath.sol\";\nimport \"../libraries/SafeERC20.sol\";\n\nimport \"./interfaces/IERC20.sol\";\nimport \"./interfaces/IJoeERC20.sol\";\nimport \"./interfaces/IJoePair.sol\";\nimport \"./interfaces/IJoeFactory.sol\";\n\ninterface IMasterChef {\n struct PoolInfo {\n IJoeERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\n }\n\n function poolLength() external view returns (uint256);\n\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function joePerSec() external view returns (uint256);\n}\n\ninterface IBoostedMasterchef {\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n uint256 factor;\n }\n\n struct PoolInfo {\n IERC20 lpToken;\n uint96 allocPoint;\n uint256 accJoePerShare;\n uint256 accJoePerFactorPerShare;\n uint64 lastRewardTimestamp;\n address rewarder;\n uint32 veJoeShareBp;\n uint256 totalFactor;\n uint256 totalLpSupply;\n }\n\n function userInfo(uint256 _pid, address user) external view returns (UserInfo memory);\n\n function pendingTokens(uint256 _pid, address user)\n external\n view\n returns (\n uint256,\n address,\n string memory,\n uint256\n );\n\n function poolLength() external view returns (uint256);\n\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function joePerSec() external view returns (uint256);\n}\n\ncontract FarmLensV2 {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n struct FarmInfo {\n uint256 id;\n uint256 allocPoint;\n address lpAddress;\n address token0Address;\n address token1Address;\n string token0Symbol;\n string token1Symbol;\n uint256 reserveUsd;\n uint256 totalSupplyScaled;\n address chefAddress;\n uint256 chefBalanceScaled;\n uint256 chefTotalAlloc;\n uint256 chefJoePerSec;\n }\n\n struct FarmInfoBMCJ {\n uint256 id;\n uint256 allocPoint;\n address lpAddress;\n address token0Address;\n address token1Address;\n string token0Symbol;\n string token1Symbol;\n uint256 reserveUsd;\n uint256 totalSupplyScaled;\n address chefAddress;\n uint256 chefBalanceScaled;\n uint256 chefTotalAlloc;\n uint256 chefJoePerSec;\n uint256 baseApr;\n uint256 averageBoostedApr;\n uint256 veJoeShareBp;\n uint256 joePriceUsd;\n\n uint256 userLp;\n uint256 userPendingJoe;\n uint256 userBoostedApr;\n uint256 userFactorShare;\n }\n\n struct AllFarmData {\n uint256 avaxPriceUsd;\n uint256 joePriceUsd;\n uint256 totalAllocChefV2;\n uint256 totalAllocChefV3;\n uint256 totalAllocBMCJ;\n uint256 joePerSecChefV2;\n uint256 joePerSecChefV3;\n uint256 joePerSecBMCJ;\n FarmInfo[] farmInfosV2;\n FarmInfo[] farmInfosV3;\n FarmInfoBMCJ[] farmInfosBMCJ;\n }\n\n struct GlobalInfo {\n address chef;\n uint256 totalAlloc;\n uint256 joePerSec;\n }\n\n /// @dev 365 * 86400, hard coding it for gas optimisation\n uint256 private constant SEC_PER_YEAR = 31536000;\n uint256 private constant BP_PRECISION = 10_000;\n uint256 private constant PRECISION = 1e18;\n\n address public immutable joe; // 0x6e84a6216eA6dACC71eE8E6b0a5B7322EEbC0fDd;\n address public immutable wavax; // 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7;\n IJoePair public immutable wavaxUsdte; // 0xeD8CBD9F0cE3C6986b22002F03c6475CEb7a6256\n IJoePair public immutable wavaxUsdce; // 0xA389f9430876455C36478DeEa9769B7Ca4E3DDB1\n IJoePair public immutable wavaxUsdc; // 0xf4003f4efbe8691b60249e6afbd307abe7758adb\n IJoeFactory public immutable joeFactory; // 0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10\n IMasterChef public immutable chefv2; // 0xd6a4F121CA35509aF06A0Be99093d08462f53052\n IMasterChef public immutable chefv3; // 0x188bED1968b795d5c9022F6a0bb5931Ac4c18F00\n IBoostedMasterchef public immutable bmcj; // Not deployed yet\n bool private immutable isWavaxToken1InWavaxUsdte;\n bool private immutable isWavaxToken1InWavaxUsdce;\n bool private immutable isWavaxToken1InWavaxUsdc;\n\n constructor(\n address _joe,\n address _wavax,\n IJoePair _wavaxUsdte,\n IJoePair _wavaxUsdce,\n IJoePair _wavaxUsdc,\n IJoeFactory _joeFactory,\n IMasterChef _chefv2,\n IMasterChef _chefv3,\n IBoostedMasterchef _bmcj\n ) public {\n joe = _joe;\n wavax = _wavax;\n wavaxUsdte = _wavaxUsdte;\n wavaxUsdce = _wavaxUsdce;\n wavaxUsdc = _wavaxUsdc;\n joeFactory = _joeFactory;\n chefv2 = _chefv2;\n chefv3 = _chefv3;\n bmcj = _bmcj;\n\n isWavaxToken1InWavaxUsdte = _wavaxUsdte.token1() == _wavax;\n isWavaxToken1InWavaxUsdce = _wavaxUsdce.token1() == _wavax;\n isWavaxToken1InWavaxUsdc = _wavaxUsdc.token1() == _wavax;\n }\n\n /// @notice Returns the price of avax in Usd\n /// @return uint256 the avax price, scaled to 18 decimals\n function getAvaxPrice() external view returns (uint256) {\n return _getAvaxPrice();\n }\n\n /// @notice Returns the derived price of token, it needs to be paired with wavax\n /// @param token The address of the token\n /// @return uint256 the token derived price, scaled to 18 decimals\n function getDerivedAvaxPriceOfToken(address token) external view returns (uint256) {\n return _getDerivedAvaxPriceOfToken(token);\n }\n\n /// @notice Returns the Usd price of token, it needs to be paired with wavax\n /// @param token The address of the token\n /// @return uint256 the Usd price of token, scaled to 18 decimals\n function getTokenPrice(address token) external view returns (uint256) {\n return _getDerivedAvaxPriceOfToken(token).mul(_getAvaxPrice()) / 1e18;\n }\n\n /// @notice Returns the farm pairs data for MCV2 and MCV3\n /// @param chef The address of the MasterChef\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\n function getMCFarmInfos(IMasterChef chef, uint256[] calldata whitelistedPids)\n external\n view\n returns (FarmInfo[] memory)\n {\n require(chef == chefv2 || chef == chefv3, \"FarmLensV2: only for MCV2 and MCV3\");\n\n uint256 avaxPrice = _getAvaxPrice();\n return _getMCFarmInfos(chef, avaxPrice, whitelistedPids);\n }\n\n /// @notice Returns the farm pairs data for BoostedMasterChefJoe\n /// @param chef The address of the MasterChef\n /// @param user The address of the user, if address(0), returns global info\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\n /// @return FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\n function getBMCJFarmInfos(\n IBoostedMasterchef chef,\n address user,\n uint256[] calldata whitelistedPids\n ) external view returns (FarmInfoBMCJ[] memory) {\n require(chef == bmcj, \"FarmLensV2: Only for BMCJ\");\n\n uint256 avaxPrice = _getAvaxPrice();\n uint256 joePrice = _getDerivedAvaxPriceOfToken(joe).mul(avaxPrice) / PRECISION;\n return _getBMCJFarmInfos(avaxPrice, joePrice, user, whitelistedPids);\n }\n\n /// @notice Get all data needed for useFarms hook.\n /// @param whitelistedPidsV2 Array of all ids of pools that are whitelisted in chefV2\n /// @param whitelistedPidsV3 Array of all ids of pools that are whitelisted in chefV3\n /// @param whitelistedPidsBMCJ Array of all ids of pools that are whitelisted in BMCJ\n /// @param user The address of the user, if address(0), returns global info\n /// @return AllFarmData The information of all the whitelisted farms of MCV2, MCV3 and BMCJ\n function getAllFarmData(\n uint256[] calldata whitelistedPidsV2,\n uint256[] calldata whitelistedPidsV3,\n uint256[] calldata whitelistedPidsBMCJ,\n address user\n ) external view returns (AllFarmData memory) {\n AllFarmData memory allFarmData;\n\n uint256 avaxPrice = _getAvaxPrice();\n uint256 joePrice = _getDerivedAvaxPriceOfToken(joe).mul(avaxPrice) / PRECISION;\n\n allFarmData.avaxPriceUsd = avaxPrice;\n allFarmData.joePriceUsd = joePrice;\n\n allFarmData.totalAllocChefV2 = chefv2.totalAllocPoint();\n allFarmData.joePerSecChefV2 = chefv2.joePerSec();\n\n allFarmData.totalAllocChefV3 = chefv3.totalAllocPoint();\n allFarmData.joePerSecChefV3 = chefv3.joePerSec();\n\n allFarmData.totalAllocBMCJ = bmcj.totalAllocPoint();\n allFarmData.joePerSecBMCJ = bmcj.joePerSec();\n\n allFarmData.farmInfosV2 = _getMCFarmInfos(chefv2, avaxPrice, whitelistedPidsV2);\n allFarmData.farmInfosV3 = _getMCFarmInfos(chefv3, avaxPrice, whitelistedPidsV3);\n allFarmData.farmInfosBMCJ = _getBMCJFarmInfos(avaxPrice, joePrice, user, whitelistedPidsBMCJ);\n\n return allFarmData;\n }\n\n /// @notice Returns the price of avax in Usd internally\n /// @return uint256 the avax price, scaled to 18 decimals\n function _getAvaxPrice() private view returns (uint256) {\n return\n _getDerivedTokenPriceOfPair(wavaxUsdte, isWavaxToken1InWavaxUsdte)\n .add(_getDerivedTokenPriceOfPair(wavaxUsdce, isWavaxToken1InWavaxUsdce))\n .add(_getDerivedTokenPriceOfPair(wavaxUsdc, isWavaxToken1InWavaxUsdc)) / 3;\n }\n\n /// @notice Returns the derived price of token in the other token\n /// @param pair The address of the pair\n /// @param derivedtoken0 If price should be derived from token0 if true, or token1 if false\n /// @return uint256 the derived price, scaled to 18 decimals\n function _getDerivedTokenPriceOfPair(IJoePair pair, bool derivedtoken0) private view returns (uint256) {\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n uint256 decimals0 = IERC20(pair.token0()).safeDecimals();\n uint256 decimals1 = IERC20(pair.token1()).safeDecimals();\n\n if (derivedtoken0) {\n return _scaleTo(reserve0, decimals1.add(18).sub(decimals0)).div(reserve1);\n } else {\n return _scaleTo(reserve1, decimals0.add(18).sub(decimals1)).div(reserve0);\n }\n }\n\n /// @notice Returns the derived price of token, it needs to be paired with wavax\n /// @param token The address of the token\n /// @return uint256 the token derived price, scaled to 18 decimals\n function _getDerivedAvaxPriceOfToken(address token) private view returns (uint256) {\n if (token == wavax) {\n return PRECISION;\n }\n IJoePair pair = IJoePair(joeFactory.getPair(token, wavax));\n if (address(pair) == address(0)) {\n return 0;\n }\n // instead of testing wavax == pair.token0(), we do the opposite to save gas\n return _getDerivedTokenPriceOfPair(pair, token == pair.token1());\n }\n\n /// @notice Returns the amount scaled to decimals\n /// @param amount The amount\n /// @param decimals The decimals to scale `amount`\n /// @return uint256 The amount scaled to decimals\n function _scaleTo(uint256 amount, uint256 decimals) private pure returns (uint256) {\n if (decimals == 0) return amount;\n return amount.mul(10**decimals);\n }\n\n /// @notice Returns the derived avax liquidity, at least one of the token needs to be paired with wavax\n /// @param pair The address of the pair\n /// @return uint256 the derived price of pair's liquidity, scaled to 18 decimals\n function _getDerivedAvaxLiquidityOfPair(IJoePair pair) private view returns (uint256) {\n address _wavax = wavax;\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n IERC20 token0 = IERC20(pair.token0());\n IERC20 token1 = IERC20(pair.token1());\n uint256 decimals0 = token0.safeDecimals();\n uint256 decimals1 = token1.safeDecimals();\n\n reserve0 = _scaleTo(reserve0, uint256(18).sub(decimals0));\n reserve1 = _scaleTo(reserve1, uint256(18).sub(decimals1));\n\n uint256 token0DerivedAvaxPrice;\n uint256 token1DerivedAvaxPrice;\n if (address(token0) == _wavax) {\n token0DerivedAvaxPrice = PRECISION;\n token1DerivedAvaxPrice = _getDerivedTokenPriceOfPair(pair, true);\n } else if (address(token1) == _wavax) {\n token0DerivedAvaxPrice = _getDerivedTokenPriceOfPair(pair, false);\n token1DerivedAvaxPrice = PRECISION;\n } else {\n token0DerivedAvaxPrice = _getDerivedAvaxPriceOfToken(address(token0));\n token1DerivedAvaxPrice = _getDerivedAvaxPriceOfToken(address(token1));\n // If one token isn't paired with wavax, then we hope that the second one is.\n // E.g, TOKEN/UsdC, token might not be paired with wavax, but UsdC is.\n // If both aren't paired with wavax, return 0\n if (token0DerivedAvaxPrice == 0) return reserve1.mul(token1DerivedAvaxPrice).mul(2) / PRECISION;\n if (token1DerivedAvaxPrice == 0) return reserve0.mul(token0DerivedAvaxPrice).mul(2) / PRECISION;\n }\n return reserve0.mul(token0DerivedAvaxPrice).add(reserve1.mul(token1DerivedAvaxPrice)) / PRECISION;\n }\n\n /// @notice Private function to return the farm pairs data for a given MasterChef (V2 or V3)\n /// @param chef The address of the MasterChef\n /// @param avaxPrice The avax price as a parameter to save gas\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\n function _getMCFarmInfos(\n IMasterChef chef,\n uint256 avaxPrice,\n uint256[] calldata whitelistedPids\n ) private view returns (FarmInfo[] memory) {\n uint256 whitelistLength = whitelistedPids.length;\n FarmInfo[] memory farmInfos = new FarmInfo[](whitelistLength);\n\n uint256 chefTotalAlloc = chef.totalAllocPoint();\n uint256 chefJoePerSec = chef.joePerSec();\n\n for (uint256 i; i < whitelistLength; i++) {\n uint256 pid = whitelistedPids[i];\n IMasterChef.PoolInfo memory pool = chef.poolInfo(pid);\n\n farmInfos[i] = _getMCFarmInfo(\n chef,\n avaxPrice,\n pid,\n IJoePair(address(pool.lpToken)),\n pool.allocPoint,\n chefTotalAlloc,\n chefJoePerSec\n );\n }\n\n return farmInfos;\n }\n\n /// @notice Helper function to return the farm info of a given pool\n /// @param chef The address of the MasterChef\n /// @param avaxPrice The avax price as a parameter to save gas\n /// @param pid The pid of the pool\n /// @param lpToken The lpToken of the pool\n /// @param allocPoint The allocPoint of the pool\n /// @return FarmInfo The information of all the whitelisted farms of MCV2 or MCV3\n function _getMCFarmInfo(\n IMasterChef chef,\n uint256 avaxPrice,\n uint256 pid,\n IJoePair lpToken,\n uint256 allocPoint,\n uint256 totalAllocPoint,\n uint256 chefJoePerSec\n ) private view returns (FarmInfo memory) {\n uint256 decimals = lpToken.decimals();\n uint256 totalSupplyScaled = _scaleTo(lpToken.totalSupply(), 18 - decimals);\n uint256 chefBalanceScaled = _scaleTo(lpToken.balanceOf(address(chef)), 18 - decimals);\n uint256 reserveUsd = _getDerivedAvaxLiquidityOfPair(lpToken).mul(avaxPrice) / PRECISION;\n IERC20 token0 = IERC20(lpToken.token0());\n IERC20 token1 = IERC20(lpToken.token1());\n\n return\n FarmInfo({\n id: pid,\n allocPoint: allocPoint,\n lpAddress: address(lpToken),\n token0Address: address(token0),\n token1Address: address(token1),\n token0Symbol: token0.safeSymbol(),\n token1Symbol: token1.safeSymbol(),\n reserveUsd: reserveUsd,\n totalSupplyScaled: totalSupplyScaled,\n chefBalanceScaled: chefBalanceScaled,\n chefAddress: address(chef),\n chefTotalAlloc: totalAllocPoint,\n chefJoePerSec: chefJoePerSec\n });\n }\n\n /// @notice Private function to return the farm pairs data for boostedMasterChef\n /// @param avaxPrice The avax price as a parameter to save gas\n /// @param joePrice The joe price as a parameter to save gas\n /// @param user The address of the user, if address(0), returns global info\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned\n /// @return FarmInfoBMCJ The information of all the whitelisted farms of BMCJ\n function _getBMCJFarmInfos(\n uint256 avaxPrice,\n uint256 joePrice,\n address user,\n uint256[] calldata whitelistedPids\n ) private view returns (FarmInfoBMCJ[] memory) {\n GlobalInfo memory globalInfo = GlobalInfo(address(bmcj), bmcj.totalAllocPoint(), bmcj.joePerSec());\n\n uint256 whitelistLength = whitelistedPids.length;\n FarmInfoBMCJ[] memory farmInfos = new FarmInfoBMCJ[](whitelistLength);\n\n for (uint256 i; i < whitelistLength; i++) {\n uint256 pid = whitelistedPids[i];\n IBoostedMasterchef.PoolInfo memory pool = IBoostedMasterchef(globalInfo.chef).poolInfo(pid);\n IBoostedMasterchef.UserInfo memory userInfo;\n userInfo = IBoostedMasterchef(globalInfo.chef).userInfo(pid, user);\n\n farmInfos[i].id = pid;\n farmInfos[i].chefAddress = globalInfo.chef;\n farmInfos[i].chefTotalAlloc = globalInfo.totalAlloc;\n farmInfos[i].chefJoePerSec = globalInfo.joePerSec;\n farmInfos[i].joePriceUsd = joePrice;\n _getBMCJFarmInfo(\n avaxPrice,\n globalInfo.joePerSec.mul(joePrice) / PRECISION,\n user,\n farmInfos[i],\n pool,\n userInfo\n );\n }\n\n return farmInfos;\n }\n\n /// @notice Helper function to return the farm info of a given pool of BMCJ\n /// @param avaxPrice The avax price as a parameter to save gas\n /// @param UsdPerSec The Usd per sec emitted to BMCJ\n /// @param userAddress The address of the user\n /// @param farmInfo The farmInfo of that pool\n /// @param user The user information\n function _getBMCJFarmInfo(\n uint256 avaxPrice,\n uint256 UsdPerSec,\n address userAddress,\n FarmInfoBMCJ memory farmInfo,\n IBoostedMasterchef.PoolInfo memory pool,\n IBoostedMasterchef.UserInfo memory user\n ) private view {\n {\n IJoePair lpToken = IJoePair(address(pool.lpToken));\n IERC20 token0 = IERC20(lpToken.token0());\n IERC20 token1 = IERC20(lpToken.token1());\n\n farmInfo.allocPoint = pool.allocPoint;\n farmInfo.lpAddress = address(lpToken);\n farmInfo.token0Address = address(token0);\n farmInfo.token1Address = address(token1);\n farmInfo.token0Symbol = token0.safeSymbol();\n farmInfo.token1Symbol = token1.safeSymbol();\n farmInfo.reserveUsd = _getDerivedAvaxLiquidityOfPair(lpToken).mul(avaxPrice) / PRECISION;\n // LP is in 18 decimals, so it's already scaled for JLP\n farmInfo.totalSupplyScaled = lpToken.totalSupply();\n farmInfo.chefBalanceScaled = pool.totalLpSupply;\n farmInfo.userLp = user.amount;\n farmInfo.veJoeShareBp = pool.veJoeShareBp;\n (farmInfo.userPendingJoe, , , ) = bmcj.pendingTokens(farmInfo.id, userAddress);\n }\n\n if (\n pool.totalLpSupply != 0 &&\n farmInfo.totalSupplyScaled != 0 &&\n farmInfo.chefTotalAlloc != 0 &&\n farmInfo.reserveUsd != 0\n ) {\n uint256 poolUsdPerYear = UsdPerSec.mul(pool.allocPoint).mul(SEC_PER_YEAR) / farmInfo.chefTotalAlloc;\n\n uint256 poolReserveUsd = farmInfo.reserveUsd.mul(farmInfo.chefBalanceScaled) / farmInfo.totalSupplyScaled;\n\n if (poolReserveUsd == 0) return;\n\n farmInfo.baseApr =\n poolUsdPerYear.mul(BP_PRECISION - pool.veJoeShareBp).mul(PRECISION) /\n poolReserveUsd /\n BP_PRECISION;\n\n if (pool.totalFactor != 0) {\n farmInfo.averageBoostedApr =\n poolUsdPerYear.mul(pool.veJoeShareBp).mul(PRECISION) /\n poolReserveUsd /\n BP_PRECISION;\n\n if (user.amount != 0 && user.factor != 0) {\n uint256 userLpUsd = user.amount.mul(farmInfo.reserveUsd) / pool.totalLpSupply;\n\n farmInfo.userBoostedApr =\n poolUsdPerYear.mul(pool.veJoeShareBp).mul(user.factor).div(pool.totalFactor).mul(PRECISION) /\n userLpUsd /\n BP_PRECISION;\n\n farmInfo.userFactorShare = user.factor.mul(PRECISION) / pool.totalFactor;\n }\n }\n }\n }\n}\n" + }, + "contracts/traderjoe/interfaces/IJoeERC20.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\ninterface IJoeERC20 {\n event Approval(address indexed owner, address indexed spender, uint256 value);\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n function name() external pure returns (string memory);\n\n function symbol() external pure returns (string memory);\n\n function decimals() external pure returns (uint8);\n\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address owner) external view returns (uint256);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 value) external returns (bool);\n\n function transfer(address to, uint256 value) external returns (bool);\n\n function transferFrom(\n address from,\n address to,\n uint256 value\n ) external returns (bool);\n\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n\n function PERMIT_TYPEHASH() external pure returns (bytes32);\n\n function nonces(address owner) external view returns (uint256);\n\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n}\n" + }, + "contracts/traderjoe/FarmLens.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\nimport \"../libraries/SafeMath.sol\";\nimport \"../libraries/SafeERC20.sol\";\n\nimport \"../interfaces/IERC20.sol\";\nimport \"./interfaces/IJoeERC20.sol\";\nimport \"./interfaces/IJoePair.sol\";\nimport \"./interfaces/IJoeFactory.sol\";\n\nimport \"../boringcrypto/BoringOwnable.sol\";\n\ninterface IMasterChef {\n struct PoolInfo {\n IJoeERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\n }\n\n function poolLength() external view returns (uint256);\n\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function joePerSec() external view returns (uint256);\n}\n\ncontract FarmLens is BoringOwnable {\n using SafeMath for uint256;\n\n address public joe; // 0x6e84a6216eA6dACC71eE8E6b0a5B7322EEbC0fDd;\n address public wavax; // 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7;\n address public wavaxUsdt; // 0xeD8CBD9F0cE3C6986b22002F03c6475CEb7a6256\n address public wavaxUsdc; // 0x87Dee1cC9FFd464B79e058ba20387c1984aed86a\n address public wavaxDai; // 0xA389f9430876455C36478DeEa9769B7Ca4E3DDB1\n IJoeFactory public joeFactory; // IJoeFactory(0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10);\n IMasterChef public chefv2; //0xd6a4F121CA35509aF06A0Be99093d08462f53052\n IMasterChef public chefv3; //0x188bED1968b795d5c9022F6a0bb5931Ac4c18F00\n\n constructor(\n address joe_,\n address wavax_,\n address wavaxUsdt_,\n address wavaxUsdc_,\n address wavaxDai_,\n IJoeFactory joeFactory_,\n IMasterChef chefv2_,\n IMasterChef chefv3_\n ) public {\n joe = joe_;\n wavax = wavax_;\n wavaxUsdt = wavaxUsdt_;\n wavaxUsdc = wavaxUsdc_;\n wavaxDai = wavaxDai_;\n joeFactory = IJoeFactory(joeFactory_);\n chefv2 = chefv2_;\n chefv3 = chefv3_;\n }\n\n /// @notice Returns price of avax in usd.\n function getAvaxPrice() public view returns (uint256) {\n uint256 priceFromWavaxUsdt = _getAvaxPrice(IJoePair(wavaxUsdt)); // 18\n uint256 priceFromWavaxUsdc = _getAvaxPrice(IJoePair(wavaxUsdc)); // 18\n uint256 priceFromWavaxDai = _getAvaxPrice(IJoePair(wavaxDai)); // 18\n\n uint256 sumPrice = priceFromWavaxUsdt.add(priceFromWavaxUsdc).add(priceFromWavaxDai); // 18\n uint256 avaxPrice = sumPrice / 3; // 18\n return avaxPrice; // 18\n }\n\n /// @notice Returns value of wavax in units of stablecoins per wavax.\n /// @param pair A wavax-stablecoin pair.\n function _getAvaxPrice(IJoePair pair) private view returns (uint256) {\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n\n if (pair.token0() == wavax) {\n reserve1 = reserve1.mul(_tokenDecimalsMultiplier(pair.token1())); // 18\n return (reserve1.mul(1e18)) / reserve0; // 18\n } else {\n reserve0 = reserve0.mul(_tokenDecimalsMultiplier(pair.token0())); // 18\n return (reserve0.mul(1e18)) / reserve1; // 18\n }\n }\n\n /// @notice Get the price of a token in Usd.\n /// @param tokenAddress Address of the token.\n function getPriceInUsd(address tokenAddress) public view returns (uint256) {\n return (getAvaxPrice().mul(getPriceInAvax(tokenAddress))) / 1e18; // 18\n }\n\n /// @notice Get the price of a token in Avax.\n /// @param tokenAddress Address of the token.\n /// @dev Need to be aware of decimals here, not always 18, it depends on the token.\n function getPriceInAvax(address tokenAddress) public view returns (uint256) {\n if (tokenAddress == wavax) {\n return 1e18;\n }\n\n IJoePair pair = IJoePair(joeFactory.getPair(tokenAddress, wavax));\n\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n address token0Address = pair.token0();\n address token1Address = pair.token1();\n\n if (token0Address == wavax) {\n reserve1 = reserve1.mul(_tokenDecimalsMultiplier(token1Address)); // 18\n return (reserve0.mul(1e18)) / reserve1; // 18\n } else {\n reserve0 = reserve0.mul(_tokenDecimalsMultiplier(token0Address)); // 18\n return (reserve1.mul(1e18)) / reserve0; // 18\n }\n }\n\n /// @notice Calculates the multiplier needed to scale a token's numerical field to 18 decimals.\n /// @param tokenAddress Address of the token.\n function _tokenDecimalsMultiplier(address tokenAddress) private pure returns (uint256) {\n uint256 decimalsNeeded = 18 - IJoeERC20(tokenAddress).decimals();\n return 1 * (10**decimalsNeeded);\n }\n\n /// @notice Calculates the reserve of a pair in usd.\n /// @param pair Pair for which the reserve will be calculated.\n function getReserveUsd(IJoePair pair) public view returns (uint256) {\n address token0Address = pair.token0();\n address token1Address = pair.token1();\n\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n\n reserve0 = reserve0.mul(_tokenDecimalsMultiplier(token0Address)); // 18\n reserve1 = reserve1.mul(_tokenDecimalsMultiplier(token1Address)); // 18\n\n uint256 token0PriceInAvax = getPriceInAvax(token0Address); // 18\n uint256 token1PriceInAvax = getPriceInAvax(token1Address); // 18\n uint256 reserve0Avax = reserve0.mul(token0PriceInAvax); // 36;\n uint256 reserve1Avax = reserve1.mul(token1PriceInAvax); // 36;\n uint256 reserveAvax = (reserve0Avax.add(reserve1Avax)) / 1e18; // 18\n uint256 reserveUsd = (reserveAvax.mul(getAvaxPrice())) / 1e18; // 18\n\n return reserveUsd; // 18\n }\n\n struct FarmPair {\n uint256 id;\n uint256 allocPoint;\n address lpAddress;\n address token0Address;\n address token1Address;\n string token0Symbol;\n string token1Symbol;\n uint256 reserveUsd;\n uint256 totalSupplyScaled;\n address chefAddress;\n uint256 chefBalanceScaled;\n uint256 chefTotalAlloc;\n uint256 chefJoePerSec;\n }\n\n /// @notice Gets the farm pair data for a given MasterChef.\n /// @param chefAddress The address of the MasterChef.\n /// @param whitelistedPids Array of all ids of pools that are whitelisted and valid to have their farm data returned.\n function getFarmPairs(address chefAddress, uint256[] calldata whitelistedPids)\n public\n view\n returns (FarmPair[] memory)\n {\n IMasterChef chef = IMasterChef(chefAddress);\n\n uint256 whitelistLength = whitelistedPids.length;\n FarmPair[] memory farmPairs = new FarmPair[](whitelistLength);\n\n for (uint256 i = 0; i < whitelistLength; i++) {\n IMasterChef.PoolInfo memory pool = chef.poolInfo(whitelistedPids[i]);\n IJoePair lpToken = IJoePair(address(pool.lpToken));\n\n //get pool information\n farmPairs[i].id = whitelistedPids[i];\n farmPairs[i].allocPoint = pool.allocPoint;\n\n // get pair information\n address lpAddress = address(lpToken);\n address token0Address = lpToken.token0();\n address token1Address = lpToken.token1();\n farmPairs[i].lpAddress = lpAddress;\n farmPairs[i].token0Address = token0Address;\n farmPairs[i].token1Address = token1Address;\n farmPairs[i].token0Symbol = IJoeERC20(token0Address).symbol();\n farmPairs[i].token1Symbol = IJoeERC20(token1Address).symbol();\n\n // calculate reserveUsd of lp\n farmPairs[i].reserveUsd = getReserveUsd(lpToken); // 18\n\n // calculate total supply of lp\n farmPairs[i].totalSupplyScaled = lpToken.totalSupply().mul(_tokenDecimalsMultiplier(lpAddress));\n\n // get masterChef data\n uint256 balance = lpToken.balanceOf(chefAddress);\n farmPairs[i].chefBalanceScaled = balance.mul(_tokenDecimalsMultiplier(lpAddress));\n farmPairs[i].chefAddress = chefAddress;\n farmPairs[i].chefTotalAlloc = chef.totalAllocPoint();\n farmPairs[i].chefJoePerSec = chef.joePerSec();\n }\n\n return farmPairs;\n }\n\n struct AllFarmData {\n uint256 avaxPriceUsd;\n uint256 joePriceUsd;\n uint256 totalAllocChefV2;\n uint256 totalAllocChefV3;\n uint256 joePerSecChefV2;\n uint256 joePerSecChefV3;\n FarmPair[] farmPairsV2;\n FarmPair[] farmPairsV3;\n }\n\n /// @notice Get all data needed for useFarms hook.\n /// @param whitelistedPidsV2 Array of all ids of pools that are whitelisted in chefV2.\n /// @param whitelistedPidsV3 Array of all ids of pools that are whitelisted in chefV3.\n function getAllFarmData(uint256[] calldata whitelistedPidsV2, uint256[] calldata whitelistedPidsV3)\n public\n view\n returns (AllFarmData memory)\n {\n AllFarmData memory allFarmData;\n\n allFarmData.avaxPriceUsd = getAvaxPrice();\n allFarmData.joePriceUsd = getPriceInUsd(joe);\n\n allFarmData.totalAllocChefV2 = IMasterChef(chefv2).totalAllocPoint();\n allFarmData.joePerSecChefV2 = IMasterChef(chefv2).joePerSec();\n\n allFarmData.totalAllocChefV3 = IMasterChef(chefv3).totalAllocPoint();\n allFarmData.joePerSecChefV3 = IMasterChef(chefv3).joePerSec();\n\n allFarmData.farmPairsV2 = getFarmPairs(address(chefv2), whitelistedPidsV2);\n allFarmData.farmPairsV3 = getFarmPairs(address(chefv3), whitelistedPidsV3);\n\n return allFarmData;\n }\n}\n" + }, + "contracts/rewarders/SimpleRewarderPerBlock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"../boringcrypto/BoringOwnable.sol\";\nimport \"../libraries/SafeERC20.sol\";\n\ninterface IRewarder {\n using SafeERC20 for IERC20;\n\n function onJoeReward(address user, uint256 newLpAmount) external;\n\n function pendingTokens(address user) external view returns (uint256 pending);\n\n function rewardToken() external view returns (IERC20);\n}\n\ninterface IMasterChefJoeV2 {\n using SafeERC20 for IERC20;\n\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this poolInfo. SUSHI to distribute per block.\n uint256 lastRewardTimestamp; // Last block timestamp that SUSHI distribution occurs.\n uint256 accJoePerShare; // Accumulated SUSHI per share, times 1e12. See below.\n }\n\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n}\n\n/**\n * This is a sample contract to be used in the MasterChefJoeV2 contract for partners to reward\n * stakers with their native token alongside JOE.\n *\n * It assumes no minting rights, so requires a set amount of YOUR_TOKEN to be transferred to this contract prior.\n * E.g. say you've allocated 100,000 XYZ to the JOE-XYZ farm over 30 days. Then you would need to transfer\n * 100,000 XYZ and set the block reward accordingly so it's fully distributed after 30 days.\n *\n */\ncontract SimpleRewarderPerBlock is IRewarder, BoringOwnable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n IERC20 public immutable override rewardToken;\n IERC20 public immutable lpToken;\n IMasterChefJoeV2 public immutable MC_V2;\n\n /// @notice Info of each MCV2 user.\n /// `amount` LP token amount the user has provided.\n /// `rewardDebt` The amount of YOUR_TOKEN entitled to the user.\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n }\n\n /// @notice Info of each MCV2 poolInfo.\n /// `accTokenPerShare` Amount of YOUR_TOKEN each LP token is worth.\n /// `lastRewardBlock` The last block YOUR_TOKEN was rewarded to the poolInfo.\n struct PoolInfo {\n uint256 accTokenPerShare;\n uint256 lastRewardBlock;\n }\n\n /// @notice Info of the poolInfo.\n PoolInfo public poolInfo;\n /// @notice Info of each user that stakes LP tokens.\n mapping(address => UserInfo) public userInfo;\n\n uint256 public tokenPerBlock;\n uint256 private constant ACC_TOKEN_PRECISION = 1e12;\n\n event OnReward(address indexed user, uint256 amount);\n event RewardRateUpdated(uint256 oldRate, uint256 newRate);\n\n modifier onlyMCV2() {\n require(msg.sender == address(MC_V2), \"onlyMCV2: only MasterChef V2 can call this function\");\n _;\n }\n\n constructor(\n IERC20 _rewardToken,\n IERC20 _lpToken,\n uint256 _tokenPerBlock,\n IMasterChefJoeV2 _MCV2\n ) public {\n require(Address.isContract(address(_rewardToken)), \"constructor: reward token must be a valid contract\");\n require(Address.isContract(address(_lpToken)), \"constructor: LP token must be a valid contract\");\n require(Address.isContract(address(_MCV2)), \"constructor: MasterChefJoeV2 must be a valid contract\");\n\n rewardToken = _rewardToken;\n lpToken = _lpToken;\n tokenPerBlock = _tokenPerBlock;\n MC_V2 = _MCV2;\n poolInfo = PoolInfo({lastRewardBlock: block.number, accTokenPerShare: 0});\n }\n\n /// @notice Update reward variables of the given poolInfo.\n /// @return pool Returns the pool that was updated.\n function updatePool() public returns (PoolInfo memory pool) {\n pool = poolInfo;\n\n if (block.number > pool.lastRewardBlock) {\n uint256 lpSupply = lpToken.balanceOf(address(MC_V2));\n\n if (lpSupply > 0) {\n uint256 blocks = block.number.sub(pool.lastRewardBlock);\n uint256 tokenReward = blocks.mul(tokenPerBlock);\n pool.accTokenPerShare = pool.accTokenPerShare.add((tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply));\n }\n\n pool.lastRewardBlock = block.number;\n poolInfo = pool;\n }\n }\n\n /// @notice Sets the distribution reward rate. This will also update the poolInfo.\n /// @param _tokenPerBlock The number of tokens to distribute per block\n function setRewardRate(uint256 _tokenPerBlock) external onlyOwner {\n updatePool();\n\n uint256 oldRate = tokenPerBlock;\n tokenPerBlock = _tokenPerBlock;\n\n emit RewardRateUpdated(oldRate, _tokenPerBlock);\n }\n\n /// @notice Function called by MasterChefJoeV2 whenever staker claims JOE harvest. Allows staker to also receive a 2nd reward token.\n /// @param _user Address of user\n /// @param _lpAmount Number of LP tokens the user has\n function onJoeReward(address _user, uint256 _lpAmount) external override onlyMCV2 {\n updatePool();\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n uint256 pending;\n // if user had deposited\n if (user.amount > 0) {\n pending = (user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n uint256 balance = rewardToken.balanceOf(address(this));\n if (pending > balance) {\n rewardToken.safeTransfer(_user, balance);\n } else {\n rewardToken.safeTransfer(_user, pending);\n }\n }\n\n user.amount = _lpAmount;\n user.rewardDebt = user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION;\n\n emit OnReward(_user, pending);\n }\n\n /// @notice View function to see pending tokens\n /// @param _user Address of user.\n /// @return pending reward for a given user.\n function pendingTokens(address _user) external view override returns (uint256 pending) {\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n\n uint256 accTokenPerShare = poolInfo.accTokenPerShare;\n uint256 lpSupply = lpToken.balanceOf(address(MC_V2));\n\n if (block.number > poolInfo.lastRewardBlock && lpSupply != 0) {\n uint256 blocks = block.number.sub(poolInfo.lastRewardBlock);\n uint256 tokenReward = blocks.mul(tokenPerBlock);\n accTokenPerShare = accTokenPerShare.add(tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply);\n }\n\n pending = (user.amount.mul(accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n }\n\n /// @notice In case rewarder is stopped before emissions finished, this function allows\n /// withdrawal of remaining tokens.\n function emergencyWithdraw() public onlyOwner {\n rewardToken.safeTransfer(address(msg.sender), rewardToken.balanceOf(address(this)));\n }\n}\n" + }, + "contracts/rewarders/MasterChefRewarderPerSec.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"../libraries/SafeERC20.sol\";\n\ninterface IRewarder {\n using SafeERC20 for IERC20;\n\n function onJoeReward(address user, uint256 newLpAmount) external;\n\n function pendingTokens(address user) external view returns (uint256 pending);\n\n function rewardToken() external view returns (IERC20);\n}\n\ninterface IMasterChef {\n struct PoolInfo {\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n }\n\n function deposit(uint256 _pid, uint256 _amount) external;\n\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n}\n\ninterface IMasterChefJoeV2 {\n using SafeERC20 for IERC20;\n\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this poolInfo. SUSHI to distribute per block.\n uint256 lastRewardTimestamp; // Last block.timestamp that SUSHI distribution occurs.\n uint256 accJoePerShare; // Accumulated SUSHI per share, times 1e12. See below.\n }\n\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n}\n\n/**\n * This is a sample contract to be used in the MasterChefJoeV2 contract for partners to reward\n * stakers with their native token alongside JOE.\n *\n * It assumes the project already has an existing MasterChef-style farm contract.\n * In which case, the init() function is called to deposit a dummy token into one\n * of the MasterChef farms so this contract can accrue rewards from that farm.\n * The contract then transfers the reward token to the user on each call to\n * onJoeReward().\n *\n */\ncontract MasterChefRewarderPerSec is IRewarder, Ownable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n IERC20 public immutable override rewardToken;\n IERC20 public immutable lpToken;\n uint256 public immutable MCV1_pid;\n IMasterChef public immutable MCV1;\n IMasterChefJoeV2 public immutable MCV2;\n\n /// @notice Info of each MCV2 user.\n /// `amount` LP token amount the user has provided.\n /// `rewardDebt` The amount of JOE entitled to the user.\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n }\n\n /// @notice Info of each MCV2 poolInfo.\n /// `accTokenPerShare` Amount of JOE each LP token is worth.\n /// `lastRewardTimestamp` The last time JOE was rewarded to the poolInfo.\n struct PoolInfo {\n uint256 accTokenPerShare;\n uint256 lastRewardTimestamp;\n uint256 allocPoint;\n }\n\n /// @notice Info of the poolInfo.\n PoolInfo public poolInfo;\n /// @notice Info of each user that stakes LP tokens.\n mapping(address => UserInfo) public userInfo;\n\n uint256 public tokenPerSec;\n uint256 private constant ACC_TOKEN_PRECISION = 1e12;\n\n event OnReward(address indexed user, uint256 amount);\n event RewardRateUpdated(uint256 oldRate, uint256 newRate);\n event AllocPointUpdated(uint256 oldAllocPoint, uint256 newAllocPoint);\n\n modifier onlyMCV2() {\n require(msg.sender == address(MCV2), \"onlyMCV2: only MasterChef V2 can call this function\");\n _;\n }\n\n constructor(\n IERC20 _rewardToken,\n IERC20 _lpToken,\n uint256 _tokenPerSec,\n uint256 _allocPoint,\n uint256 _MCV1_pid,\n IMasterChef _MCV1,\n IMasterChefJoeV2 _MCV2\n ) public {\n require(Address.isContract(address(_rewardToken)), \"constructor: reward token must be a valid contract\");\n require(Address.isContract(address(_lpToken)), \"constructor: LP token must be a valid contract\");\n require(Address.isContract(address(_MCV1)), \"constructor: MasterChef must be a valid contract\");\n require(Address.isContract(address(_MCV2)), \"constructor: MasterChefJoeV2 must be a valid contract\");\n\n rewardToken = _rewardToken;\n lpToken = _lpToken;\n tokenPerSec = _tokenPerSec;\n MCV1_pid = _MCV1_pid;\n MCV1 = _MCV1;\n MCV2 = _MCV2;\n poolInfo = PoolInfo({lastRewardTimestamp: block.timestamp, accTokenPerShare: 0, allocPoint: _allocPoint});\n }\n\n /// @notice Deposits a dummy token to a MaterChefV1 farm so that this contract can claim reward tokens.\n /// @param dummyToken The address of the dummy ERC20 token to deposit into MCV1.\n function init(IERC20 dummyToken) external {\n uint256 balance = dummyToken.balanceOf(msg.sender);\n require(balance > 0, \"init: Balance must exceed 0\");\n dummyToken.safeTransferFrom(msg.sender, balance);\n dummyToken.approve(address(MCV1), balance);\n MCV1.deposit(MCV1_pid, balance);\n }\n\n /// @notice Update reward variables of the given poolInfo.\n /// @return pool Returns the pool that was updated.\n function updatePool() public returns (PoolInfo memory pool) {\n pool = poolInfo;\n\n if (block.timestamp > pool.lastRewardTimestamp) {\n uint256 lpSupply = lpToken.balanceOf(address(MCV2));\n\n if (lpSupply > 0) {\n uint256 timeElapsed = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 tokenReward = timeElapsed.mul(tokenPerSec).mul(pool.allocPoint).div(MCV1.totalAllocPoint());\n pool.accTokenPerShare = pool.accTokenPerShare.add((tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply));\n }\n\n pool.lastRewardTimestamp = block.timestamp;\n poolInfo = pool;\n }\n }\n\n /// @notice Sets the distribution reward rate. This will also update the poolInfo.\n /// @param _tokenPerSec The number of tokens to distribute per block\n function setRewardRate(uint256 _tokenPerSec) external onlyOwner {\n updatePool();\n\n uint256 oldRate = tokenPerSec;\n tokenPerSec = _tokenPerSec;\n\n emit RewardRateUpdated(oldRate, _tokenPerSec);\n }\n\n /// @notice Sets the allocation point. THis will also update the poolInfo.\n /// @param _allocPoint The new allocation point of the pool\n function setAllocPoint(uint256 _allocPoint) external onlyOwner {\n updatePool();\n\n uint256 oldAllocPoint = poolInfo.allocPoint;\n poolInfo.allocPoint = _allocPoint;\n\n emit AllocPointUpdated(oldAllocPoint, _allocPoint);\n }\n\n /// @notice Claims reward tokens from MCV1 farm.\n function harvestFromMasterChefV1() public {\n MCV1.deposit(MCV1_pid, 0);\n }\n\n /// @notice Function called by MasterChefJoeV2 whenever staker claims JOE harvest. Allows staker to also receive a 2nd reward token.\n /// @param _user Address of user\n /// @param _lpAmount Number of LP tokens the user has\n function onJoeReward(address _user, uint256 _lpAmount) external override onlyMCV2 {\n updatePool();\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n uint256 pendingBal;\n // if user had deposited\n if (user.amount > 0) {\n harvestFromMasterChefV1();\n pendingBal = (user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n uint256 rewardBal = rewardToken.balanceOf(address(this));\n if (pendingBal > rewardBal) {\n rewardToken.safeTransfer(_user, rewardBal);\n } else {\n rewardToken.safeTransfer(_user, pendingBal);\n }\n }\n\n user.amount = _lpAmount;\n user.rewardDebt = user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION;\n\n emit OnReward(_user, pendingBal);\n }\n\n /// @notice View function to see pending tokens\n /// @param _user Address of user.\n /// @return pending reward for a given user.\n function pendingTokens(address _user) external view override returns (uint256 pending) {\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n\n uint256 accTokenPerShare = pool.accTokenPerShare;\n uint256 lpSupply = lpToken.balanceOf(address(MCV2));\n\n if (block.timestamp > pool.lastRewardTimestamp && lpSupply != 0) {\n uint256 blocks = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 tokenReward = blocks.mul(tokenPerSec).mul(pool.allocPoint).div(MCV1.totalAllocPoint());\n accTokenPerShare = accTokenPerShare.add(tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply);\n }\n\n pending = (user.amount.mul(accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n }\n}\n" + }, + "contracts/rewarders/MasterChefRewarderPerBlock.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"../libraries/SafeERC20.sol\";\nimport \"../interfaces/IRewarder.sol\";\n\n\ninterface IMasterChef {\n struct PoolInfo {\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n }\n\n function deposit(uint256 _pid, uint256 _amount) external;\n\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n}\n\ninterface IMasterChefJoeV2 {\n using SafeERC20 for IERC20;\n\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this poolInfo. SUSHI to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that SUSHI distribution occurs.\n uint256 accJoePerShare; // Accumulated SUSHI per share, times 1e12. See below.\n }\n\n function poolInfo(uint256 pid) external view returns (PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n}\n\n/**\n * This is a sample contract to be used in the MasterChefJoeV2 contract for partners to reward\n * stakers with their native token alongside JOE.\n *\n * It assumes the project already has an existing MasterChef-style farm contract.\n * In which case, the init() function is called to deposit a dummy token into one\n * of the MasterChef farms so this contract can accrue rewards from that farm.\n * The contract then transfers the reward token to the user on each call to\n * onJoeReward().\n *\n */\ncontract MasterChefRewarderPerBlock is IRewarder, Ownable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n IERC20 public immutable override rewardToken;\n IERC20 public immutable lpToken;\n uint256 public immutable MCV1_pid;\n IMasterChef public immutable MCV1;\n IMasterChefJoeV2 public immutable MCV2;\n\n /// @notice Info of each MCV2 user.\n /// `amount` LP token amount the user has provided.\n /// `rewardDebt` The amount of JOE entitled to the user.\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n }\n\n /// @notice Info of each MCV2 poolInfo.\n /// `accTokenPerShare` Amount of JOE each LP token is worth.\n /// `lastRewardBlock` The last block JOE was rewarded to the poolInfo.\n struct PoolInfo {\n uint256 accTokenPerShare;\n uint256 lastRewardBlock;\n uint256 allocPoint;\n }\n\n /// @notice Info of the poolInfo.\n PoolInfo public poolInfo;\n /// @notice Info of each user that stakes LP tokens.\n mapping(address => UserInfo) public userInfo;\n\n uint256 public tokenPerBlock;\n uint256 private constant ACC_TOKEN_PRECISION = 1e12;\n\n event OnReward(address indexed user, uint256 amount);\n event RewardRateUpdated(uint256 oldRate, uint256 newRate);\n event AllocPointUpdated(uint256 oldAllocPoint, uint256 newAllocPoint);\n\n modifier onlyMCV2() {\n require(msg.sender == address(MCV2), \"onlyMCV2: only MasterChef V2 can call this function\");\n _;\n }\n\n constructor(\n IERC20 _rewardToken,\n IERC20 _lpToken,\n uint256 _tokenPerBlock,\n uint256 _allocPoint,\n uint256 _MCV1_pid,\n IMasterChef _MCV1,\n IMasterChefJoeV2 _MCV2\n ) public {\n require(Address.isContract(address(_rewardToken)), \"constructor: reward token must be a valid contract\");\n require(Address.isContract(address(_lpToken)), \"constructor: LP token must be a valid contract\");\n require(Address.isContract(address(_MCV1)), \"constructor: MasterChef must be a valid contract\");\n require(Address.isContract(address(_MCV2)), \"constructor: MasterChefJoeV2 must be a valid contract\");\n\n rewardToken = _rewardToken;\n lpToken = _lpToken;\n tokenPerBlock = _tokenPerBlock;\n MCV1_pid = _MCV1_pid;\n MCV1 = _MCV1;\n MCV2 = _MCV2;\n poolInfo = PoolInfo({lastRewardBlock: block.number, accTokenPerShare: 0, allocPoint: _allocPoint});\n }\n\n /// @notice Deposits a dummy token to a MaterChefV1 farm so that this contract can claim reward tokens.\n /// @param dummyToken The address of the dummy ERC20 token to deposit into MCV1.\n function init(IERC20 dummyToken) external {\n uint256 balance = dummyToken.balanceOf(msg.sender);\n require(balance > 0, \"init: Balance must exceed 0\");\n dummyToken.safeTransferFrom(msg.sender, balance);\n dummyToken.approve(address(MCV1), balance);\n MCV1.deposit(MCV1_pid, balance);\n }\n\n /// @notice Update reward variables of the given poolInfo.\n /// @return pool Returns the pool that was updated.\n function updatePool() public returns (PoolInfo memory pool) {\n pool = poolInfo;\n\n if (block.number > pool.lastRewardBlock) {\n uint256 lpSupply = lpToken.balanceOf(address(MCV2));\n\n if (lpSupply > 0) {\n uint256 blocks = block.number.sub(pool.lastRewardBlock);\n uint256 tokenReward = blocks.mul(tokenPerBlock).mul(pool.allocPoint).div(MCV1.totalAllocPoint());\n pool.accTokenPerShare = pool.accTokenPerShare.add((tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply));\n }\n\n pool.lastRewardBlock = block.number;\n poolInfo = pool;\n }\n }\n\n /// @notice Sets the distribution reward rate. This will also update the poolInfo.\n /// @param _tokenPerBlock The number of tokens to distribute per block\n function setRewardRate(uint256 _tokenPerBlock) external onlyOwner {\n updatePool();\n\n uint256 oldRate = tokenPerBlock;\n tokenPerBlock = _tokenPerBlock;\n\n emit RewardRateUpdated(oldRate, _tokenPerBlock);\n }\n\n /// @notice Sets the allocation point. THis will also update the poolInfo.\n /// @param _allocPoint The new allocation point of the pool\n function setAllocPoint(uint256 _allocPoint) external onlyOwner {\n updatePool();\n\n uint256 oldAllocPoint = poolInfo.allocPoint;\n poolInfo.allocPoint = _allocPoint;\n\n emit AllocPointUpdated(oldAllocPoint, _allocPoint);\n }\n\n /// @notice Claims reward tokens from MCV1 farm.\n function harvestFromMasterChefV1() public {\n MCV1.deposit(MCV1_pid, 0);\n }\n\n /// @notice Function called by MasterChefJoeV2 whenever staker claims JOE harvest. Allows staker to also receive a 2nd reward token.\n /// @param _user Address of user\n /// @param _lpAmount Number of LP tokens the user has\n function onJoeReward(address _user, uint256 _lpAmount) external override onlyMCV2 {\n updatePool();\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n uint256 pendingBal;\n // if user had deposited\n if (user.amount > 0) {\n harvestFromMasterChefV1();\n pendingBal = (user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n uint256 rewardBal = rewardToken.balanceOf(address(this));\n if (pendingBal > rewardBal) {\n rewardToken.safeTransfer(_user, rewardBal);\n } else {\n rewardToken.safeTransfer(_user, pendingBal);\n }\n }\n\n user.amount = _lpAmount;\n user.rewardDebt = user.amount.mul(pool.accTokenPerShare) / ACC_TOKEN_PRECISION;\n\n emit OnReward(_user, pendingBal);\n }\n\n /// @notice View function to see pending tokens\n /// @param _user Address of user.\n /// @return pending reward for a given user.\n function pendingTokens(address _user) external view override returns (uint256 pending) {\n PoolInfo memory pool = poolInfo;\n UserInfo storage user = userInfo[_user];\n\n uint256 accTokenPerShare = pool.accTokenPerShare;\n uint256 lpSupply = lpToken.balanceOf(address(MCV2));\n\n if (block.number > pool.lastRewardBlock && lpSupply != 0) {\n uint256 blocks = block.number.sub(pool.lastRewardBlock);\n uint256 tokenReward = blocks.mul(tokenPerBlock).mul(pool.allocPoint).div(MCV1.totalAllocPoint());\n accTokenPerShare = accTokenPerShare.add(tokenReward.mul(ACC_TOKEN_PRECISION) / lpSupply);\n }\n\n pending = (user.amount.mul(accTokenPerShare) / ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n }\n}\n" + }, + "contracts/MasterChefJoeV3.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/EnumerableSet.sol\";\nimport \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\nimport \"./interfaces/IERC20.sol\";\n\ninterface IMasterChef {\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\n }\n\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function joePerSec() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n\n function devPercent() external view returns (uint256);\n\n function treasuryPercent() external view returns (uint256);\n\n function investorPercent() external view returns (uint256);\n}\n\ninterface IRewarder {\n function onJoeReward(address user, uint256 newLpAmount) external;\n\n function pendingTokens(address user) external view returns (uint256 pending);\n\n function rewardToken() external view returns (IERC20);\n}\n\nlibrary BoringERC20 {\n bytes4 private constant SIG_SYMBOL = 0x95d89b41; // symbol()\n bytes4 private constant SIG_NAME = 0x06fdde03; // name()\n bytes4 private constant SIG_DECIMALS = 0x313ce567; // decimals()\n bytes4 private constant SIG_TRANSFER = 0xa9059cbb; // transfer(address,uint256)\n bytes4 private constant SIG_TRANSFER_FROM = 0x23b872dd; // transferFrom(address,address,uint256)\n\n function returnDataToString(bytes memory data) internal pure returns (string memory) {\n if (data.length >= 64) {\n return abi.decode(data, (string));\n } else if (data.length == 32) {\n uint8 i = 0;\n while (i < 32 && data[i] != 0) {\n i++;\n }\n bytes memory bytesArray = new bytes(i);\n for (i = 0; i < 32 && data[i] != 0; i++) {\n bytesArray[i] = data[i];\n }\n return string(bytesArray);\n } else {\n return \"???\";\n }\n }\n\n /// @notice Provides a safe ERC20.symbol version which returns '???' as fallback string.\n /// @param token The address of the ERC-20 token contract.\n /// @return (string) Token symbol.\n function safeSymbol(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_SYMBOL));\n return success ? returnDataToString(data) : \"???\";\n }\n\n /// @notice Provides a safe ERC20.name version which returns '???' as fallback string.\n /// @param token The address of the ERC-20 token contract.\n /// @return (string) Token name.\n function safeName(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_NAME));\n return success ? returnDataToString(data) : \"???\";\n }\n\n /// @notice Provides a safe ERC20.decimals version which returns '18' as fallback value.\n /// @param token The address of the ERC-20 token contract.\n /// @return (uint8) Token decimals.\n function safeDecimals(IERC20 token) internal view returns (uint8) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(SIG_DECIMALS));\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\n }\n\n /// @notice Provides a safe ERC20.transfer version for different ERC-20 implementations.\n /// Reverts on a failed transfer.\n /// @param token The address of the ERC-20 token.\n /// @param to Transfer tokens to.\n /// @param amount The token amount.\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(SIG_TRANSFER, to, amount));\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"BoringERC20: Transfer failed\");\n }\n\n /// @notice Provides a safe ERC20.transferFrom version for different ERC-20 implementations.\n /// Reverts on a failed transfer.\n /// @param token The address of the ERC-20 token.\n /// @param from Transfer tokens from.\n /// @param to Transfer tokens to.\n /// @param amount The token amount.\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 amount\n ) internal {\n (bool success, bytes memory data) = address(token).call(\n abi.encodeWithSelector(SIG_TRANSFER_FROM, from, to, amount)\n );\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"BoringERC20: TransferFrom failed\");\n }\n}\n\n/// @notice The (older) MasterChefJoeV2 contract gives out a constant number of JOE tokens per block.\n/// It is the only address with minting rights for JOE.\n/// The idea for this MasterChefJoeV3 (MCJV3) contract is therefore to be the owner of a dummy token\n/// that is deposited into the MasterChefJoeV2 (MCJV2) contract.\n/// The allocation point for this pool on MCJV3 is the total allocation point for all pools that receive double incentives.\ncontract MasterChefJoeV3 is Ownable, ReentrancyGuard {\n using SafeMath for uint256;\n using BoringERC20 for IERC20;\n using EnumerableSet for EnumerableSet.AddressSet;\n\n /// @notice Info of each MCJV3 user.\n /// `amount` LP token amount the user has provided.\n /// `rewardDebt` The amount of JOE entitled to the user.\n struct UserInfo {\n uint256 amount;\n uint256 rewardDebt;\n }\n\n /// @notice Info of each MCJV3 pool.\n /// `allocPoint` The amount of allocation points assigned to the pool.\n /// Also known as the amount of JOE to distribute per block.\n struct PoolInfo {\n IERC20 lpToken;\n uint256 accJoePerShare;\n uint256 lastRewardTimestamp;\n uint256 allocPoint;\n IRewarder rewarder;\n }\n\n /// @notice Address of MCJV2 contract.\n IMasterChef public immutable MASTER_CHEF_V2;\n /// @notice Address of JOE contract.\n IERC20 public immutable JOE;\n /// @notice The index of MCJV3 master pool in MCJV2\n uint256 public immutable MASTER_PID;\n /// @notice Info of each MCJV3 pool.\n PoolInfo[] public poolInfo;\n // Set of all LP tokens that have been added as pools\n EnumerableSet.AddressSet private lpTokens;\n /// @notice Info of each user that stakes LP tokens.\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n /// @dev Total allocation points. Must be the sum of all allocation points in all pools.\n uint256 public totalAllocPoint;\n uint256 private constant ACC_TOKEN_PRECISION = 1e18;\n\n event Add(uint256 indexed pid, uint256 allocPoint, IERC20 indexed lpToken, IRewarder indexed rewarder);\n event Set(uint256 indexed pid, uint256 allocPoint, IRewarder indexed rewarder, bool overwrite);\n event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\n event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event UpdatePool(uint256 indexed pid, uint256 lastRewardTimestamp, uint256 lpSupply, uint256 accJoePerShare);\n event Harvest(address indexed user, uint256 indexed pid, uint256 amount);\n event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event Init();\n\n /// @param _MASTER_CHEF_V2 The JoeSwap MCJV2 contract address.\n /// @param _joe The JOE token contract address.\n /// @param _MASTER_PID The pool ID of the dummy token on the base MCJV2 contract.\n constructor(\n IMasterChef _MASTER_CHEF_V2,\n IERC20 _joe,\n uint256 _MASTER_PID\n ) public {\n MASTER_CHEF_V2 = _MASTER_CHEF_V2;\n JOE = _joe;\n MASTER_PID = _MASTER_PID;\n }\n\n /// @notice Deposits a dummy token to `MASTER_CHEF_V2` MCJV2. This is required because MCJV2 holds the minting rights for JOE.\n /// Any balance of transaction sender in `dummyToken` is transferred.\n /// The allocation point for the pool on MCJV2 is the total allocation point for all pools that receive double incentives.\n /// @param dummyToken The address of the ERC-20 token to deposit into MCJV2.\n function init(IERC20 dummyToken) external onlyOwner {\n uint256 balance = dummyToken.balanceOf(msg.sender);\n require(balance != 0, \"MasterChefV2: Balance must exceed 0\");\n dummyToken.safeTransferFrom(msg.sender, address(this), balance);\n dummyToken.approve(address(MASTER_CHEF_V2), balance);\n MASTER_CHEF_V2.deposit(MASTER_PID, balance);\n emit Init();\n }\n\n /// @notice Returns the number of MCJV3 pools.\n function poolLength() external view returns (uint256 pools) {\n pools = poolInfo.length;\n }\n\n /// @notice Add a new LP to the pool. Can only be called by the owner.\n /// DO NOT add the same LP token more than once. Rewards will be messed up if you do.\n /// @param allocPoint AP of the new pool.\n /// @param _lpToken Address of the LP ERC-20 token.\n /// @param _rewarder Address of the rewarder delegate.\n function add(\n uint256 allocPoint,\n IERC20 _lpToken,\n IRewarder _rewarder\n ) external onlyOwner {\n require(!lpTokens.contains(address(_lpToken)), \"add: LP already added\");\n // Sanity check to ensure _lpToken is an ERC20 token\n _lpToken.balanceOf(address(this));\n // Sanity check if we add a rewarder\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(address(0), 0);\n }\n\n uint256 lastRewardTimestamp = block.timestamp;\n totalAllocPoint = totalAllocPoint.add(allocPoint);\n\n poolInfo.push(\n PoolInfo({\n lpToken: _lpToken,\n allocPoint: allocPoint,\n lastRewardTimestamp: lastRewardTimestamp,\n accJoePerShare: 0,\n rewarder: _rewarder\n })\n );\n lpTokens.add(address(_lpToken));\n emit Add(poolInfo.length.sub(1), allocPoint, _lpToken, _rewarder);\n }\n\n /// @notice Update the given pool's JOE allocation point and `IRewarder` contract. Can only be called by the owner.\n /// @param _pid The index of the pool. See `poolInfo`.\n /// @param _allocPoint New AP of the pool.\n /// @param _rewarder Address of the rewarder delegate.\n /// @param overwrite True if _rewarder should be `set`. Otherwise `_rewarder` is ignored.\n function set(\n uint256 _pid,\n uint256 _allocPoint,\n IRewarder _rewarder,\n bool overwrite\n ) external onlyOwner {\n PoolInfo memory pool = poolInfo[_pid];\n totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);\n pool.allocPoint = _allocPoint;\n if (overwrite) {\n _rewarder.onJoeReward(address(0), 0); // sanity check\n pool.rewarder = _rewarder;\n }\n poolInfo[_pid] = pool;\n emit Set(_pid, _allocPoint, overwrite ? _rewarder : pool.rewarder, overwrite);\n }\n\n /// @notice View function to see pending JOE on frontend.\n /// @param _pid The index of the pool. See `poolInfo`.\n /// @param _user Address of user.\n /// @return pendingJoe JOE reward for a given user.\n // bonusTokenAddress The address of the bonus reward.\n // bonusTokenSymbol The symbol of the bonus token.\n // pendingBonusToken The amount of bonus rewards pending.\n function pendingTokens(uint256 _pid, address _user)\n external\n view\n returns (\n uint256 pendingJoe,\n address bonusTokenAddress,\n string memory bonusTokenSymbol,\n uint256 pendingBonusToken\n )\n {\n PoolInfo memory pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_user];\n uint256 accJoePerShare = pool.accJoePerShare;\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (block.timestamp > pool.lastRewardTimestamp && lpSupply != 0) {\n uint256 secondsElapsed = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 joeReward = secondsElapsed.mul(joePerSec()).mul(pool.allocPoint).div(totalAllocPoint);\n accJoePerShare = accJoePerShare.add(joeReward.mul(ACC_TOKEN_PRECISION).div(lpSupply));\n }\n pendingJoe = user.amount.mul(accJoePerShare).div(ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n\n // If it's a double reward farm, we return info about the bonus token\n if (address(pool.rewarder) != address(0)) {\n bonusTokenAddress = address(pool.rewarder.rewardToken());\n bonusTokenSymbol = IERC20(pool.rewarder.rewardToken()).safeSymbol();\n pendingBonusToken = pool.rewarder.pendingTokens(_user);\n }\n }\n\n /// @notice Update reward variables for all pools. Be careful of gas spending!\n /// @param pids Pool IDs of all to be updated. Make sure to update all active pools.\n function massUpdatePools(uint256[] calldata pids) external {\n uint256 len = pids.length;\n for (uint256 i = 0; i < len; ++i) {\n updatePool(pids[i]);\n }\n }\n\n /// @notice Calculates and returns the `amount` of JOE per block.\n function joePerSec() public view returns (uint256 amount) {\n uint256 total = 1000;\n uint256 lpPercent = total.sub(MASTER_CHEF_V2.devPercent()).sub(MASTER_CHEF_V2.treasuryPercent()).sub(\n MASTER_CHEF_V2.investorPercent()\n );\n uint256 lpShare = MASTER_CHEF_V2.joePerSec().mul(lpPercent).div(total);\n amount = lpShare.mul(MASTER_CHEF_V2.poolInfo(MASTER_PID).allocPoint).div(MASTER_CHEF_V2.totalAllocPoint());\n }\n\n /// @notice Update reward variables of the given pool.\n /// @param pid The index of the pool. See `poolInfo`.\n function updatePool(uint256 pid) public {\n PoolInfo memory pool = poolInfo[pid];\n if (block.timestamp > pool.lastRewardTimestamp) {\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (lpSupply > 0) {\n uint256 secondsElapsed = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 joeReward = secondsElapsed.mul(joePerSec()).mul(pool.allocPoint).div(totalAllocPoint);\n pool.accJoePerShare = pool.accJoePerShare.add((joeReward.mul(ACC_TOKEN_PRECISION).div(lpSupply)));\n }\n pool.lastRewardTimestamp = block.timestamp;\n poolInfo[pid] = pool;\n emit UpdatePool(pid, pool.lastRewardTimestamp, lpSupply, pool.accJoePerShare);\n }\n }\n\n /// @notice Deposit LP tokens to MCJV3 for JOE allocation.\n /// @param pid The index of the pool. See `poolInfo`.\n /// @param amount LP token amount to deposit.\n function deposit(uint256 pid, uint256 amount) external nonReentrant {\n harvestFromMasterChef();\n updatePool(pid);\n PoolInfo memory pool = poolInfo[pid];\n UserInfo storage user = userInfo[pid][msg.sender];\n\n if (user.amount > 0) {\n // Harvest JOE\n uint256 pending = user.amount.mul(pool.accJoePerShare).div(ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n JOE.safeTransfer(msg.sender, pending);\n emit Harvest(msg.sender, pid, pending);\n }\n\n uint256 balanceBefore = pool.lpToken.balanceOf(address(this));\n pool.lpToken.safeTransferFrom(msg.sender, address(this), amount);\n uint256 receivedAmount = pool.lpToken.balanceOf(address(this)).sub(balanceBefore);\n\n // Effects\n user.amount = user.amount.add(receivedAmount);\n user.rewardDebt = user.amount.mul(pool.accJoePerShare).div(ACC_TOKEN_PRECISION);\n\n // Interactions\n IRewarder _rewarder = pool.rewarder;\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(msg.sender, user.amount);\n }\n\n emit Deposit(msg.sender, pid, receivedAmount);\n }\n\n /// @notice Withdraw LP tokens from MCJV3.\n /// @param pid The index of the pool. See `poolInfo`.\n /// @param amount LP token amount to withdraw.\n function withdraw(uint256 pid, uint256 amount) external nonReentrant {\n harvestFromMasterChef();\n updatePool(pid);\n PoolInfo memory pool = poolInfo[pid];\n UserInfo storage user = userInfo[pid][msg.sender];\n\n if (user.amount > 0) {\n // Harvest JOE\n uint256 pending = user.amount.mul(pool.accJoePerShare).div(ACC_TOKEN_PRECISION).sub(user.rewardDebt);\n JOE.safeTransfer(msg.sender, pending);\n emit Harvest(msg.sender, pid, pending);\n }\n\n // Effects\n user.amount = user.amount.sub(amount);\n user.rewardDebt = user.amount.mul(pool.accJoePerShare).div(ACC_TOKEN_PRECISION);\n\n // Interactions\n IRewarder _rewarder = pool.rewarder;\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(msg.sender, user.amount);\n }\n\n pool.lpToken.safeTransfer(msg.sender, amount);\n\n emit Withdraw(msg.sender, pid, amount);\n }\n\n /// @notice Harvests JOE from `MASTER_CHEF_V2` MCJV2 and pool `MASTER_PID` to this MCJV3 contract.\n function harvestFromMasterChef() public {\n MASTER_CHEF_V2.deposit(MASTER_PID, 0);\n }\n\n /// @notice Withdraw without caring about rewards. EMERGENCY ONLY.\n /// @param pid The index of the pool. See `poolInfo`.\n function emergencyWithdraw(uint256 pid) external nonReentrant {\n PoolInfo memory pool = poolInfo[pid];\n UserInfo storage user = userInfo[pid][msg.sender];\n uint256 amount = user.amount;\n user.amount = 0;\n user.rewardDebt = 0;\n\n IRewarder _rewarder = pool.rewarder;\n if (address(_rewarder) != address(0)) {\n _rewarder.onJoeReward(msg.sender, 0);\n }\n\n // Note: transfer can fail or succeed if `amount` is zero.\n pool.lpToken.safeTransfer(msg.sender, amount);\n emit EmergencyWithdraw(msg.sender, pid, amount);\n }\n}\n" + }, + "contracts/interfaces/IPair.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"./IERC20.sol\";\n\ninterface IPair is IERC20 {\n function token0() external view returns (address);\n\n function token1() external view returns (address);\n\n function getReserves()\n external\n view\n returns (\n uint112,\n uint112,\n uint32\n );\n}\n" + }, + "contracts/libraries/BoringPair.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\nimport \"../interfaces/IPair.sol\";\nimport \"../interfaces/IFactory.sol\";\n\nlibrary BoringPair {\n function factory(IPair pair) internal view returns (IFactory) {\n (bool success, bytes memory data) = address(pair).staticcall(abi.encodeWithSelector(0xc45a0155));\n return success && data.length == 32 ? abi.decode(data, (IFactory)) : IFactory(0);\n }\n}\n" + }, + "contracts/interfaces/IFactory.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\ninterface IFactory {\n function allPairsLength() external view returns (uint256);\n\n function allPairs(uint256 i) external view returns (address);\n\n function getPair(address token0, address token1) external view returns (address);\n\n function feeTo() external view returns (address);\n\n function feeToSetter() external view returns (address);\n}\n" + }, + "contracts/boringcrypto/BoringCryptoTokenScanner.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n/**\n *Submitted for verification at Etherscan.io on 2020-09-18\n */\n\npragma solidity ^0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"../interfaces/IFactory.sol\";\n\ninterface IERC20 {\n function name() external view returns (string memory);\n\n function symbol() external view returns (string memory);\n\n function decimals() external view returns (uint256);\n\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n\n function transfer(address recipient, uint256 amount) external returns (bool);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 amount) external returns (bool);\n\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) external returns (bool);\n\n function owner() external view returns (address);\n\n event Transfer(address indexed from, address indexed to, uint256 value);\n event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n\nlibrary BoringERC20 {\n function returnDataToString(bytes memory data) internal pure returns (string memory) {\n if (data.length >= 64) {\n return abi.decode(data, (string));\n } else if (data.length == 32) {\n uint8 i = 0;\n while (i < 32 && data[i] != 0) {\n i++;\n }\n bytes memory bytesArray = new bytes(i);\n for (i = 0; i < 32 && data[i] != 0; i++) {\n bytesArray[i] = data[i];\n }\n return string(bytesArray);\n } else {\n return \"???\";\n }\n }\n\n function symbol(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x95d89b41));\n return success ? returnDataToString(data) : \"???\";\n }\n\n function name(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x06fdde03));\n return success ? returnDataToString(data) : \"???\";\n }\n\n function decimals(IERC20 token) internal view returns (uint8) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x313ce567));\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\n }\n\n function DOMAIN_SEPARATOR(IERC20 token) internal view returns (bytes32) {\n (bool success, bytes memory data) = address(token).staticcall{gas: 10000}(abi.encodeWithSelector(0x3644e515));\n return success && data.length == 32 ? abi.decode(data, (bytes32)) : bytes32(0);\n }\n\n function nonces(IERC20 token, address owner) internal view returns (uint256) {\n (bool success, bytes memory data) = address(token).staticcall{gas: 5000}(\n abi.encodeWithSelector(0x7ecebe00, owner)\n );\n // Use max uint256 to signal failure to retrieve nonce (probably not supported)\n return success && data.length == 32 ? abi.decode(data, (uint256)) : uint256(-1);\n }\n}\n\ninterface IMasterChef {\n function BONUS_MULTIPLIER() external view returns (uint256);\n\n function devaddr() external view returns (address);\n\n function owner() external view returns (address);\n\n function startTimestamp() external view returns (uint256);\n\n function joe() external view returns (address);\n\n function joePerSec() external view returns (uint256);\n\n function totalAllocPoint() external view returns (uint256);\n\n function poolLength() external view returns (uint256);\n\n function poolInfo(uint256 nr)\n external\n view\n returns (\n address,\n uint256,\n uint256,\n uint256\n );\n\n function userInfo(uint256 nr, address who) external view returns (uint256, uint256);\n\n function pendingTokens(uint256 pid, address who)\n external\n view\n returns (\n uint256,\n address,\n string memory,\n uint256\n );\n}\n\ninterface IPair is IERC20 {\n function token0() external view returns (address);\n\n function token1() external view returns (address);\n\n function getReserves()\n external\n view\n returns (\n uint112,\n uint112,\n uint32\n );\n}\n\ncontract BoringCryptoTokenScanner {\n using SafeMath for uint256;\n\n struct Balance {\n address token;\n uint256 balance;\n }\n\n struct BalanceFull {\n address token;\n uint256 balance;\n uint256 rate;\n }\n\n struct TokenInfo {\n address token;\n uint256 decimals;\n string name;\n string symbol;\n }\n\n function getTokenInfo(address[] calldata addresses) public view returns (TokenInfo[] memory) {\n TokenInfo[] memory infos = new TokenInfo[](addresses.length);\n\n for (uint256 i = 0; i < addresses.length; i++) {\n IERC20 token = IERC20(addresses[i]);\n infos[i].token = address(token);\n\n infos[i].name = token.name();\n infos[i].symbol = token.symbol();\n infos[i].decimals = token.decimals();\n }\n\n return infos;\n }\n\n function findBalances(address who, address[] calldata addresses) public view returns (Balance[] memory) {\n uint256 balanceCount;\n\n for (uint256 i = 0; i < addresses.length; i++) {\n if (IERC20(addresses[i]).balanceOf(who) > 0) {\n balanceCount++;\n }\n }\n\n Balance[] memory balances = new Balance[](balanceCount);\n\n balanceCount = 0;\n for (uint256 i = 0; i < addresses.length; i++) {\n IERC20 token = IERC20(addresses[i]);\n uint256 balance = token.balanceOf(who);\n if (balance > 0) {\n balances[balanceCount].token = address(token);\n balances[balanceCount].balance = token.balanceOf(who);\n balanceCount++;\n }\n }\n\n return balances;\n }\n\n function getBalances(\n address who,\n address[] calldata addresses,\n IFactory factory,\n address currency\n ) public view returns (BalanceFull[] memory) {\n BalanceFull[] memory balances = new BalanceFull[](addresses.length);\n\n for (uint256 i = 0; i < addresses.length; i++) {\n IERC20 token = IERC20(addresses[i]);\n balances[i].token = address(token);\n balances[i].balance = token.balanceOf(who);\n\n IPair pair = IPair(factory.getPair(addresses[i], currency));\n if (address(pair) != address(0)) {\n uint256 reserveCurrency;\n uint256 reserveToken;\n if (pair.token0() == currency) {\n (reserveCurrency, reserveToken, ) = pair.getReserves();\n } else {\n (reserveToken, reserveCurrency, ) = pair.getReserves();\n }\n balances[i].rate = (reserveToken * 1e18) / reserveCurrency;\n }\n }\n\n return balances;\n }\n\n struct Factory {\n IFactory factory;\n uint256 allPairsLength;\n address feeTo;\n address feeToSetter;\n }\n\n function getFactoryInfo(IFactory[] calldata addresses) public view returns (Factory[] memory) {\n Factory[] memory factories = new Factory[](addresses.length);\n\n for (uint256 i = 0; i < addresses.length; i++) {\n IFactory factory = addresses[i];\n factories[i].factory = factory;\n\n factories[i].allPairsLength = factory.allPairsLength();\n factories[i].feeTo = factory.feeTo();\n factories[i].feeToSetter = factory.feeToSetter();\n }\n\n return factories;\n }\n\n struct Pair {\n address token;\n address token0;\n address token1;\n }\n\n function getPairs(\n IFactory factory,\n uint256 fromID,\n uint256 toID\n ) public view returns (Pair[] memory) {\n if (toID == 0) {\n toID = factory.allPairsLength();\n }\n\n Pair[] memory pairs = new Pair[](toID - fromID);\n\n for (uint256 id = fromID; id < toID; id++) {\n address token = factory.allPairs(id);\n uint256 i = id - fromID;\n pairs[i].token = token;\n pairs[i].token0 = IPair(token).token0();\n pairs[i].token1 = IPair(token).token1();\n }\n return pairs;\n }\n\n function findPairs(\n address who,\n IFactory factory,\n uint256 fromID,\n uint256 toID\n ) public view returns (Pair[] memory) {\n if (toID == 0) {\n toID = factory.allPairsLength();\n }\n\n uint256 pairCount;\n\n for (uint256 id = fromID; id < toID; id++) {\n address token = factory.allPairs(id);\n if (IERC20(token).balanceOf(who) > 0) {\n pairCount++;\n }\n }\n\n Pair[] memory pairs = new Pair[](pairCount);\n\n pairCount = 0;\n for (uint256 id = fromID; id < toID; id++) {\n address token = factory.allPairs(id);\n uint256 balance = IERC20(token).balanceOf(who);\n if (balance > 0) {\n pairs[pairCount].token = token;\n pairs[pairCount].token0 = IPair(token).token0();\n pairs[pairCount].token1 = IPair(token).token1();\n pairCount++;\n }\n }\n\n return pairs;\n }\n\n struct PairFull {\n address token;\n address token0;\n address token1;\n uint256 reserve0;\n uint256 reserve1;\n uint256 totalSupply;\n uint256 balance;\n }\n\n function getPairsFull(address who, address[] calldata addresses) public view returns (PairFull[] memory) {\n PairFull[] memory pairs = new PairFull[](addresses.length);\n for (uint256 i = 0; i < addresses.length; i++) {\n address token = addresses[i];\n pairs[i].token = token;\n pairs[i].token0 = IPair(token).token0();\n pairs[i].token1 = IPair(token).token1();\n (uint256 reserve0, uint256 reserve1, ) = IPair(token).getReserves();\n pairs[i].reserve0 = reserve0;\n pairs[i].reserve1 = reserve1;\n pairs[i].balance = IERC20(token).balanceOf(who);\n }\n return pairs;\n }\n}\n" + }, + "contracts/boringcrypto/BoringCryptoDashboardV2.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n/**\n *Submitted for verification at Etherscan.io on 2020-10-09\n */\n\npragma solidity ^0.6.12;\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"../interfaces/IFactory.sol\";\n\ninterface IERC20 {\n function name() external view returns (string memory);\n\n function symbol() external view returns (string memory);\n\n function decimals() external view returns (uint256);\n\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n\n function transfer(address recipient, uint256 amount) external returns (bool);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 amount) external returns (bool);\n\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) external returns (bool);\n\n function owner() external view returns (address);\n\n event Transfer(address indexed from, address indexed to, uint256 value);\n event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n\nlibrary BoringERC20 {\n function returnDataToString(bytes memory data) internal pure returns (string memory) {\n if (data.length >= 64) {\n return abi.decode(data, (string));\n } else if (data.length == 32) {\n uint8 i = 0;\n while (i < 32 && data[i] != 0) {\n i++;\n }\n bytes memory bytesArray = new bytes(i);\n for (i = 0; i < 32 && data[i] != 0; i++) {\n bytesArray[i] = data[i];\n }\n return string(bytesArray);\n } else {\n return \"???\";\n }\n }\n\n function symbol(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x95d89b41));\n return success ? returnDataToString(data) : \"???\";\n }\n\n function name(IERC20 token) internal view returns (string memory) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x06fdde03));\n return success ? returnDataToString(data) : \"???\";\n }\n\n function decimals(IERC20 token) internal view returns (uint8) {\n (bool success, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(0x313ce567));\n return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\n }\n\n function DOMAIN_SEPARATOR(IERC20 token) internal view returns (bytes32) {\n (bool success, bytes memory data) = address(token).staticcall{gas: 10000}(abi.encodeWithSelector(0x3644e515));\n return success && data.length == 32 ? abi.decode(data, (bytes32)) : bytes32(0);\n }\n\n function nonces(IERC20 token, address owner) internal view returns (uint256) {\n (bool success, bytes memory data) = address(token).staticcall{gas: 5000}(\n abi.encodeWithSelector(0x7ecebe00, owner)\n );\n // Use max uint256 to signal failure to retrieve nonce (probably not supported)\n return success && data.length == 32 ? abi.decode(data, (uint256)) : uint256(-1);\n }\n}\n\ninterface IMasterChef {\n function BONUS_MULTIPLIER() external view returns (uint256);\n\n function devaddr() external view returns (address);\n\n function owner() external view returns (address);\n\n function startTimestamp() external view returns (uint256);\n\n function joe() external view returns (address);\n\n function joePerSec() external view returns (uint256);\n\n function totalAllocPoint() external view returns (uint256);\n\n function poolLength() external view returns (uint256);\n\n function poolInfo(uint256 nr)\n external\n view\n returns (\n address,\n uint256,\n uint256,\n uint256\n );\n\n function userInfo(uint256 nr, address who) external view returns (uint256, uint256);\n\n function pendingTokens(uint256 pid, address who)\n external\n view\n returns (\n uint256,\n address,\n string memory,\n uint256\n );\n}\n\ninterface IPair is IERC20 {\n function token0() external view returns (address);\n\n function token1() external view returns (address);\n\n function getReserves()\n external\n view\n returns (\n uint112,\n uint112,\n uint32\n );\n}\n\ncontract BoringCryptoDashboardV2 {\n using SafeMath for uint256;\n\n struct PairFull {\n address token;\n address token0;\n address token1;\n uint256 reserve0;\n uint256 reserve1;\n uint256 totalSupply;\n uint256 balance;\n }\n\n function getPairsFull(address who, address[] calldata addresses) public view returns (PairFull[] memory) {\n PairFull[] memory pairs = new PairFull[](addresses.length);\n for (uint256 i = 0; i < addresses.length; i++) {\n address token = addresses[i];\n pairs[i].token = token;\n pairs[i].token0 = IPair(token).token0();\n pairs[i].token1 = IPair(token).token1();\n (uint256 reserve0, uint256 reserve1, ) = IPair(token).getReserves();\n pairs[i].reserve0 = reserve0;\n pairs[i].reserve1 = reserve1;\n pairs[i].balance = IERC20(token).balanceOf(who);\n pairs[i].totalSupply = IERC20(token).totalSupply();\n }\n return pairs;\n }\n\n struct PoolsInfo {\n uint256 totalAllocPoint;\n uint256 poolLength;\n }\n\n struct PoolInfo {\n uint256 pid;\n IPair lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. SUSHIs to distribute per block.\n address token0;\n address token1;\n }\n\n IMasterChef chef;\n IFactory pangolinFactory;\n IFactory joeFactory;\n address wavax;\n\n constructor(\n address _chef,\n address _pangolinFactory,\n address _joeFactory,\n address _wavax\n ) public {\n chef = IMasterChef(_chef);\n pangolinFactory = IFactory(_pangolinFactory);\n joeFactory = IFactory(_joeFactory);\n wavax = _wavax;\n }\n\n function getPools(uint256[] calldata pids) public view returns (PoolsInfo memory, PoolInfo[] memory) {\n PoolsInfo memory info;\n info.totalAllocPoint = chef.totalAllocPoint();\n uint256 poolLength = chef.poolLength();\n info.poolLength = poolLength;\n\n PoolInfo[] memory pools = new PoolInfo[](pids.length);\n\n for (uint256 i = 0; i < pids.length; i++) {\n pools[i].pid = pids[i];\n (address lpToken, uint256 allocPoint, , ) = chef.poolInfo(pids[i]);\n IPair pair = IPair(lpToken);\n pools[i].lpToken = pair;\n pools[i].allocPoint = allocPoint;\n\n pools[i].token0 = pair.token0();\n pools[i].token1 = pair.token1();\n }\n return (info, pools);\n }\n\n function findPools(address who, uint256[] calldata pids) public view returns (PoolInfo[] memory) {\n uint256 count;\n\n for (uint256 i = 0; i < pids.length; i++) {\n (uint256 balance, ) = chef.userInfo(pids[i], who);\n if (balance > 0) {\n count++;\n }\n }\n\n PoolInfo[] memory pools = new PoolInfo[](count);\n\n count = 0;\n for (uint256 i = 0; i < pids.length; i++) {\n (uint256 balance, ) = chef.userInfo(pids[i], who);\n if (balance > 0) {\n pools[count].pid = pids[i];\n (address lpToken, uint256 allocPoint, , ) = chef.poolInfo(pids[i]);\n IPair pair = IPair(lpToken);\n pools[count].lpToken = pair;\n pools[count].allocPoint = allocPoint;\n\n pools[count].token0 = pair.token0();\n pools[count].token1 = pair.token1();\n count++;\n }\n }\n\n return pools;\n }\n\n function getAVAXRate(address token) public view returns (uint256) {\n uint256 avax_rate = 1e18;\n if (token != wavax) {\n IPair pairPangolin;\n IPair pairJoe;\n pairPangolin = IPair(IFactory(pangolinFactory).getPair(token, wavax));\n pairJoe = IPair(IFactory(joeFactory).getPair(token, wavax));\n if (address(pairPangolin) == address(0) && address(pairJoe) == address(0)) {\n return 0;\n }\n\n uint112 reserve0Pangolin;\n uint112 reserve1Pangolin;\n uint112 reserve0Joe;\n uint112 reserve1Joe;\n\n if (address(pairPangolin) != address(0)) {\n (reserve0Pangolin, reserve1Pangolin, ) = pairPangolin.getReserves();\n }\n if (address(pairJoe) != address(0)) {\n (reserve0Joe, reserve1Joe, ) = pairJoe.getReserves();\n }\n\n if (address(pairJoe) == address(0) || reserve0Pangolin > reserve0Joe || reserve1Pangolin > reserve1Joe) {\n if (pairPangolin.token0() == wavax) {\n avax_rate = uint256(reserve1Pangolin).mul(1e18).div(reserve0Pangolin);\n } else {\n avax_rate = uint256(reserve0Pangolin).mul(1e18).div(reserve1Pangolin);\n }\n } else {\n if (pairJoe.token0() == wavax) {\n avax_rate = uint256(reserve1Joe).mul(1e18).div(reserve0Joe);\n } else {\n avax_rate = uint256(reserve0Joe).mul(1e18).div(reserve1Joe);\n }\n }\n }\n return avax_rate;\n }\n\n struct UserPoolInfo {\n uint256 pid;\n uint256 balance; // Balance of pool tokens\n uint256 totalSupply; // Token staked lp tokens\n uint256 lpBalance; // Balance of lp tokens not staked\n uint256 lpTotalSupply; // TotalSupply of lp tokens\n uint256 lpAllowance; // LP tokens approved for masterchef\n uint256 reserve0;\n uint256 reserve1;\n uint256 token0rate;\n uint256 token1rate;\n uint256 rewardDebt;\n uint256 pending; // Pending JOE\n }\n\n function pollPools(address who, uint256[] calldata pids) public view returns (UserPoolInfo[] memory) {\n UserPoolInfo[] memory pools = new UserPoolInfo[](pids.length);\n\n for (uint256 i = 0; i < pids.length; i++) {\n (uint256 amount, ) = chef.userInfo(pids[i], who);\n pools[i].balance = amount;\n (uint256 pendingJoe, , , ) = chef.pendingTokens(pids[i], who);\n pools[i].pending = pendingJoe;\n\n (address lpToken, , , ) = chef.poolInfo(pids[i]);\n pools[i].pid = pids[i];\n IPair pair = IPair(lpToken);\n pools[i].totalSupply = pair.balanceOf(address(chef));\n pools[i].lpAllowance = pair.allowance(who, address(chef));\n pools[i].lpBalance = pair.balanceOf(who);\n pools[i].lpTotalSupply = pair.totalSupply();\n pools[i].token0rate = getAVAXRate(pair.token0());\n pools[i].token1rate = getAVAXRate(pair.token1());\n\n (uint112 reserve0, uint112 reserve1, ) = pair.getReserves();\n pools[i].reserve0 = reserve0;\n pools[i].reserve1 = reserve1;\n }\n return pools;\n }\n}\n" + }, + "contracts/JoeVote.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"./interfaces/IPair.sol\";\nimport \"./interfaces/IBar.sol\";\n\ninterface IMasterChef {\n function userInfo(uint256 pid, address owner) external view returns (uint256, uint256);\n}\n\ncontract JoeVote {\n using SafeMath for uint256;\n\n IPair pair; // JOE-AVAX LP\n IBar bar;\n IERC20 joe;\n IMasterChef chef;\n uint256 pid; // Pool ID of the JOE-AVAX LP in MasterChefV2\n\n function name() public pure returns (string memory) {\n return \"JoeVote\";\n }\n\n function symbol() public pure returns (string memory) {\n return \"JOEVOTE\";\n }\n\n function decimals() public pure returns (uint8) {\n return 18;\n }\n\n constructor(\n address _pair,\n address _bar,\n address _joe,\n address _chef,\n uint256 _pid\n ) public {\n pair = IPair(_pair);\n bar = IBar(_bar);\n joe = IERC20(_joe);\n chef = IMasterChef(_chef);\n pid = _pid;\n }\n\n function totalSupply() public view returns (uint256) {\n (uint256 lp_totalJoe, , ) = pair.getReserves();\n uint256 xjoe_totalJoe = joe.balanceOf(address(bar));\n\n return lp_totalJoe.mul(2).add(xjoe_totalJoe);\n }\n\n function balanceOf(address owner) public view returns (uint256) {\n //////////////////////////\n // Get balance from LPs //\n //////////////////////////\n uint256 lp_totalJoe = joe.balanceOf(address(pair));\n uint256 lp_total = pair.totalSupply();\n uint256 lp_balance = pair.balanceOf(owner);\n\n // Add staked balance\n (uint256 lp_stakedBalance, ) = chef.userInfo(pid, owner);\n lp_balance = lp_balance.add(lp_stakedBalance);\n\n // LP voting power is 2x the users JOE share in the pool.\n uint256 lp_powah = lp_totalJoe.mul(lp_balance).div(lp_total).mul(2);\n\n ///////////////////////////\n // Get balance from xJOE //\n ///////////////////////////\n\n uint256 xjoe_balance = bar.balanceOf(owner);\n uint256 xjoe_total = bar.totalSupply();\n uint256 xjoe_totalJoe = joe.balanceOf(address(bar));\n\n // xJOE voting power is the users JOE share in the bar\n uint256 xjoe_powah = xjoe_totalJoe.mul(xjoe_balance).div(xjoe_total);\n\n //////////////////////////\n // Get balance from JOE //\n //////////////////////////\n\n uint256 joe_balance = joe.balanceOf(owner);\n\n return lp_powah.add(xjoe_powah).add(joe_balance);\n }\n\n function allowance(address, address) public pure returns (uint256) {\n return 0;\n }\n\n function transfer(address, uint256) public pure returns (bool) {\n return false;\n }\n\n function approve(address, uint256) public pure returns (bool) {\n return false;\n }\n\n function transferFrom(\n address,\n address,\n uint256\n ) public pure returns (bool) {\n return false;\n }\n}\n" + }, + "contracts/interfaces/IBar.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\ninterface IBar {\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n}\n" + }, + "contracts/boringcrypto/BoringBatchable.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\n// solhint-disable avoid-low-level-calls\n// solhint-disable no-inline-assembly\n\n// Audit on 5-Jan-2021 by Keno and BoringCrypto\n// WARNING!!!\n// Combining BoringBatchable with msg.value can cause double spending issues\n// https://www.paradigm.xyz/2021/08/two-rights-might-make-a-wrong/\n\nimport \"../interfaces/IERC20.sol\";\n\ncontract BaseBoringBatchable {\n /// @dev Helper function to extract a useful revert message from a failed call.\n /// If the returned data is malformed or not correctly abi encoded then this call can fail itself.\n function _getRevertMsg(bytes memory _returnData) internal pure returns (string memory) {\n // If the _res length is less than 68, then the transaction failed silently (without a revert message)\n if (_returnData.length < 68) return \"Transaction reverted silently\";\n\n assembly {\n // Slice the sighash.\n _returnData := add(_returnData, 0x04)\n }\n return abi.decode(_returnData, (string)); // All that remains is the revert string\n }\n\n /// @notice Allows batched call to self (this contract).\n /// @param calls An array of inputs for each call.\n /// @param revertOnFail If True then reverts after a failed call and stops doing further calls.\n // F1: External is ok here because this is the batch function, adding it to a batch makes no sense\n // F2: Calls in the batch may be payable, delegatecall operates in the same context, so each call in the batch has access to msg.value\n // C3: The length of the loop is fully under user control, so can't be exploited\n // C7: Delegatecall is only used on the same contract, so it's safe\n function batch(bytes[] calldata calls, bool revertOnFail) external payable {\n for (uint256 i = 0; i < calls.length; i++) {\n (bool success, bytes memory result) = address(this).delegatecall(calls[i]);\n if (!success && revertOnFail) {\n revert(_getRevertMsg(result));\n }\n }\n }\n}\n\ncontract BoringBatchable is BaseBoringBatchable {\n /// @notice Call wrapper that performs `ERC20.permit` on `token`.\n /// Lookup `IERC20.permit`.\n // F6: Parameters can be used front-run the permit and the user's permit will fail (due to nonce or other revert)\n // if part of a batch this could be used to grief once as the second call would not need the permit\n function permitToken(\n IERC20 token,\n address from,\n address to,\n uint256 amount,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) public {\n token.permit(from, to, amount, deadline, v, r, s);\n }\n}\n" + }, + "contracts/MasterChefJoe.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/utils/EnumerableSet.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./JoeToken.sol\";\n\n// MasterChefJoe is a boss. He says \"go f your blocks lego boy, I'm gonna use timestamp instead\".\n// And to top it off, it takes no risks. Because the biggest risk is operator error.\n// So we make it virtually impossible for the operator of this contract to cause a bug with people's harvests.\n//\n// Note that it's ownable and the owner wields tremendous power. The ownership\n// will be transferred to a governance smart contract once JOE is sufficiently\n// distributed and the community can show to govern itself.\n//\n// With thanks to the Lydia Finance team.\n//\n// Godspeed and may the 10x be with you.\ncontract MasterChefJoe is Ownable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n // Info of each user.\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n //\n // We do some fancy math here. Basically, any point in time, the amount of JOEs\n // entitled to a user but is pending to be distributed is:\n //\n // pending reward = (user.amount * pool.accJoePerShare) - user.rewardDebt\n //\n // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:\n // 1. The pool's `accJoePerShare` (and `lastRewardTimestamp`) gets updated.\n // 2. User receives the pending reward sent to his/her address.\n // 3. User's `amount` gets updated.\n // 4. User's `rewardDebt` gets updated.\n }\n\n // Info of each pool.\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOEs to distribute per second.\n uint256 lastRewardTimestamp; // Last timestamp that JOEs distribution occurs.\n uint256 accJoePerShare; // Accumulated JOEs per share, times 1e12. See below.\n }\n\n // The JOE TOKEN!\n JoeToken public joe;\n // Dev address.\n address public devaddr;\n // Treasury address.\n address public treasuryaddr;\n // JOE tokens created per second.\n uint256 public joePerSec;\n // Percentage of pool rewards that goto the devs.\n uint256 public devPercent; // 20%\n // Percentage of pool rewards that goes to the treasury.\n uint256 public treasuryPercent; // 20%\n\n // Info of each pool.\n PoolInfo[] public poolInfo;\n // Mapping to check which LP tokens have been added as pools.\n mapping(IERC20 => bool) public isPool;\n // Info of each user that stakes LP tokens.\n mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n // Total allocation points. Must be the sum of all allocation points in all pools.\n uint256 public totalAllocPoint = 0;\n // The timestamp when JOE mining starts.\n uint256 public startTimestamp;\n\n event Add(address indexed lpToken, uint256 allocPoint);\n event Set(uint256 indexed pid, uint256 allocPoint);\n event Deposit(address indexed user, uint256 indexed pid, uint256 amount);\n event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);\n event SetDevAddress(address indexed oldAddress, address indexed newAddress);\n event UpdateEmissionRate(address indexed user, uint256 _joePerSec);\n\n constructor(\n JoeToken _joe,\n address _devaddr,\n address _treasuryaddr,\n uint256 _joePerSec,\n uint256 _startTimestamp,\n uint256 _devPercent,\n uint256 _treasuryPercent\n ) public {\n require(0 <= _devPercent && _devPercent <= 1000, \"constructor: invalid dev percent value\");\n require(0 <= _treasuryPercent && _treasuryPercent <= 1000, \"constructor: invalid treasury percent value\");\n require(_devPercent + _treasuryPercent <= 1000, \"constructor: total percent over max\");\n joe = _joe;\n devaddr = _devaddr;\n treasuryaddr = _treasuryaddr;\n joePerSec = _joePerSec;\n startTimestamp = _startTimestamp;\n devPercent = _devPercent;\n treasuryPercent = _treasuryPercent;\n }\n\n function poolLength() external view returns (uint256) {\n return poolInfo.length;\n }\n\n // Add a new lp to the pool. Can only be called by the owner.\n // XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.\n function add(uint256 _allocPoint, IERC20 _lpToken) public onlyOwner {\n require(!isPool[_lpToken], \"add: LP already added\");\n massUpdatePools();\n uint256 lastRewardTimestamp = block.timestamp > startTimestamp ? block.timestamp : startTimestamp;\n totalAllocPoint = totalAllocPoint.add(_allocPoint);\n poolInfo.push(\n PoolInfo({\n lpToken: _lpToken,\n allocPoint: _allocPoint,\n lastRewardTimestamp: lastRewardTimestamp,\n accJoePerShare: 0\n })\n );\n isPool[_lpToken] = true;\n emit Add(address(_lpToken), _allocPoint);\n }\n\n // Update the given pool's JOE allocation point. Can only be called by the owner.\n function set(uint256 _pid, uint256 _allocPoint) public onlyOwner {\n massUpdatePools();\n totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);\n poolInfo[_pid].allocPoint = _allocPoint;\n emit Set(_pid, _allocPoint);\n }\n\n // View function to see pending JOEs on frontend.\n function pendingJoe(uint256 _pid, address _user) external view returns (uint256) {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][_user];\n uint256 accJoePerShare = pool.accJoePerShare;\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (block.timestamp > pool.lastRewardTimestamp && lpSupply != 0) {\n uint256 multiplier = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 joeReward = multiplier\n .mul(joePerSec)\n .mul(pool.allocPoint)\n .div(totalAllocPoint)\n .mul(1000 - devPercent - treasuryPercent)\n .div(1000);\n accJoePerShare = accJoePerShare.add(joeReward.mul(1e12).div(lpSupply));\n }\n return user.amount.mul(accJoePerShare).div(1e12).sub(user.rewardDebt);\n }\n\n // Update reward variables for all pools. Be careful of gas spending!\n function massUpdatePools() public {\n uint256 length = poolInfo.length;\n for (uint256 pid = 0; pid < length; ++pid) {\n updatePool(pid);\n }\n }\n\n // Update reward variables of the given pool to be up-to-date.\n function updatePool(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n if (block.timestamp <= pool.lastRewardTimestamp) {\n return;\n }\n uint256 lpSupply = pool.lpToken.balanceOf(address(this));\n if (lpSupply == 0) {\n pool.lastRewardTimestamp = block.timestamp;\n return;\n }\n uint256 multiplier = block.timestamp.sub(pool.lastRewardTimestamp);\n uint256 joeReward = multiplier.mul(joePerSec).mul(pool.allocPoint).div(totalAllocPoint);\n uint256 lpPercent = 1000 - devPercent - treasuryPercent;\n joe.mint(devaddr, joeReward.mul(devPercent).div(1000));\n joe.mint(treasuryaddr, joeReward.mul(treasuryPercent).div(1000));\n joe.mint(address(this), joeReward.mul(lpPercent).div(1000));\n pool.accJoePerShare = pool.accJoePerShare.add(joeReward.mul(1e12).div(lpSupply).mul(lpPercent).div(1000));\n pool.lastRewardTimestamp = block.timestamp;\n }\n\n // Deposit LP tokens to MasterChef for JOE allocation.\n function deposit(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n updatePool(_pid);\n if (user.amount > 0) {\n uint256 pending = user.amount.mul(pool.accJoePerShare).div(1e12).sub(user.rewardDebt);\n safeJoeTransfer(msg.sender, pending);\n }\n pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);\n user.amount = user.amount.add(_amount);\n user.rewardDebt = user.amount.mul(pool.accJoePerShare).div(1e12);\n emit Deposit(msg.sender, _pid, _amount);\n }\n\n // Withdraw LP tokens from MasterChef.\n function withdraw(uint256 _pid, uint256 _amount) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n require(user.amount >= _amount, \"withdraw: not good\");\n\n updatePool(_pid);\n uint256 pending = user.amount.mul(pool.accJoePerShare).div(1e12).sub(user.rewardDebt);\n safeJoeTransfer(msg.sender, pending);\n user.amount = user.amount.sub(_amount);\n pool.lpToken.safeTransfer(address(msg.sender), _amount);\n user.rewardDebt = user.amount.mul(pool.accJoePerShare).div(1e12);\n emit Withdraw(msg.sender, _pid, _amount);\n }\n\n // Withdraw without caring about rewards. EMERGENCY ONLY.\n function emergencyWithdraw(uint256 _pid) public {\n PoolInfo storage pool = poolInfo[_pid];\n UserInfo storage user = userInfo[_pid][msg.sender];\n pool.lpToken.safeTransfer(address(msg.sender), user.amount);\n emit EmergencyWithdraw(msg.sender, _pid, user.amount);\n user.amount = 0;\n user.rewardDebt = 0;\n }\n\n // Safe joe transfer function, just in case if rounding error causes pool to not have enough JOEs.\n function safeJoeTransfer(address _to, uint256 _amount) internal {\n uint256 joeBal = joe.balanceOf(address(this));\n if (_amount > joeBal) {\n joe.transfer(_to, joeBal);\n } else {\n joe.transfer(_to, _amount);\n }\n }\n\n // Update dev address by the previous dev.\n function dev(address _devaddr) public {\n require(msg.sender == devaddr, \"dev: wut?\");\n devaddr = _devaddr;\n emit SetDevAddress(msg.sender, _devaddr);\n }\n\n function setDevPercent(uint256 _newDevPercent) public onlyOwner {\n require(0 <= _newDevPercent && _newDevPercent <= 1000, \"setDevPercent: invalid percent value\");\n require(treasuryPercent + _newDevPercent <= 1000, \"setDevPercent: total percent over max\");\n devPercent = _newDevPercent;\n }\n\n function setTreasuryPercent(uint256 _newTreasuryPercent) public onlyOwner {\n require(0 <= _newTreasuryPercent && _newTreasuryPercent <= 1000, \"setTreasuryPercent: invalid percent value\");\n require(devPercent + _newTreasuryPercent <= 1000, \"setTreasuryPercent: total percent over max\");\n treasuryPercent = _newTreasuryPercent;\n }\n\n // Pancake has to add hidden dummy pools inorder to alter the emission,\n // here we make it simple and transparent to all.\n function updateEmissionRate(uint256 _joePerSec) public onlyOwner {\n massUpdatePools();\n joePerSec = _joePerSec;\n emit UpdateEmissionRate(msg.sender, _joePerSec);\n }\n}\n" + }, + "contracts/Cliff.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/math/Math.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\n\n/**\n * @title Cliff\n * @dev A token holder contract that can release its token balance with a cliff period.\n * Optionally revocable by the owner.\n */\ncontract Cliff {\n using SafeERC20 for IERC20;\n using SafeMath for uint256;\n\n uint256 public constant SECONDS_PER_MONTH = 30 days;\n\n event Released(uint256 amount);\n\n // beneficiary of tokens after they are released\n address public immutable beneficiary;\n IERC20 public immutable token;\n\n uint256 public immutable cliffInMonths;\n uint256 public immutable startTimestamp;\n uint256 public released;\n\n /**\n * @dev Creates a cliff contract that locks its balance of any ERC20 token and\n * only allows release to the beneficiary once the cliff has passed.\n * @param _beneficiary address of the beneficiary to whom vested tokens are transferred\n * @param _cliffInMonths duration in months of the cliff in which tokens will begin to vest\n */\n constructor(\n address _token,\n address _beneficiary,\n uint256 _startTimestamp,\n uint256 _cliffInMonths\n ) public {\n require(_beneficiary != address(0), \"Cliff: Beneficiary cannot be empty\");\n\n token = IERC20(_token);\n beneficiary = _beneficiary;\n cliffInMonths = _cliffInMonths;\n startTimestamp = _startTimestamp == 0 ? blockTimestamp() : _startTimestamp;\n }\n\n /**\n * @notice Transfers vested tokens to beneficiary.\n */\n function release() external {\n uint256 vested = vestedAmount();\n require(vested > 0, \"Cliff: No tokens to release\");\n\n released = released.add(vested);\n token.safeTransfer(beneficiary, vested);\n\n emit Released(vested);\n }\n\n /**\n * @dev Calculates the amount that has already vested but hasn't been released yet.\n */\n function vestedAmount() public view returns (uint256) {\n if (blockTimestamp() < startTimestamp) {\n return 0;\n }\n\n uint256 elapsedTime = blockTimestamp().sub(startTimestamp);\n uint256 elapsedMonths = elapsedTime.div(SECONDS_PER_MONTH);\n\n if (elapsedMonths < cliffInMonths) {\n return 0;\n } else {\n return token.balanceOf(address(this));\n }\n }\n\n function blockTimestamp() public view virtual returns (uint256) {\n return block.timestamp;\n }\n}\n" + }, + "@openzeppelin/contracts/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return a >= b ? a : b;\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return a < b ? a : b;\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow, so we distribute\n return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);\n }\n}\n" + }, + "contracts/JoeMakerV2.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// P1 - P3: OK\npragma solidity 0.6.12;\n\nimport \"./libraries/SafeMath.sol\";\nimport \"./libraries/SafeERC20.sol\";\n\nimport \"./traderjoe/interfaces/IERC20.sol\";\nimport \"./traderjoe/interfaces/IJoeERC20.sol\";\nimport \"./traderjoe/interfaces/IJoePair.sol\";\nimport \"./traderjoe/interfaces/IJoeFactory.sol\";\n\nimport \"./boringcrypto/BoringOwnable.sol\";\n\n// JoeMakerV2 is MasterJoe's left hand and kinda a wizard. He can cook up Joe from pretty much anything!\n// This contract handles \"serving up\" rewards for xJoe holders by trading tokens collected from fees for Joe.\n\n// T1 - T4: OK\ncontract JoeMakerV2 is BoringOwnable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n /* ========== CONSTANT VARIABLES ========== */\n\n IJoeFactory public immutable factory;\n address public immutable bar;\n address private immutable joe;\n address private immutable wavax;\n\n mapping(address => address) internal _bridges;\n\n event LogBridgeSet(address indexed token, address indexed bridge);\n\n event LogConvert(\n address indexed server,\n address indexed token0,\n address indexed token1,\n uint256 amount0,\n uint256 amount1,\n uint256 amountJOE\n );\n\n /* ========== CONSTRUCTOR ========== */\n\n constructor(\n address _factory,\n address _bar,\n address _joe,\n address _wavax\n ) public {\n factory = IJoeFactory(_factory);\n bar = _bar;\n joe = _joe;\n wavax = _wavax;\n }\n\n /* ========== External Functions ========== */\n\n // F3: _convert is separate to save gas by only checking the 'onlyEOA' modifier once in case of convertMultiple\n // F6: There is an exploit to add lots of JOE to the bar, run convert, then remove the JOE again.\n // As the size of the JoeBar has grown, this requires large amounts of funds and isn't super profitable anymore\n // The onlyEOA modifier prevents this being done with a flash loan.\n function convert(address token0, address token1) external onlyEOA {\n _convert(token0, token1);\n }\n\n function convertMultiple(address[] calldata token0, address[] calldata token1) external onlyEOA {\n // TODO: This can be optimized a fair bit, but this is safer and simpler for now\n uint256 len = token0.length;\n for (uint256 i = 0; i < len; i++) {\n _convert(token0[i], token1[i]);\n }\n }\n\n /* ========== Modifiers ========== */\n\n // It's not a fool proof solution, but it prevents flash loans, so here it's ok to use tx.origin\n modifier onlyEOA() {\n // Try to make flash-loan exploit harder to do by only allowing externally owned addresses.\n require(msg.sender == tx.origin, \"JoeMakerV2: must use EOA\");\n _;\n }\n\n /* ========== Public Functions ========== */\n\n function bridgeFor(address token) public view returns (address bridge) {\n bridge = _bridges[token];\n if (bridge == address(0)) {\n bridge = wavax;\n }\n }\n\n /* ========== Internal Functions ========== */\n\n function _convert(address token0, address token1) internal {\n // Interactions\n // S1 - S4: OK\n IJoePair pair = IJoePair(factory.getPair(token0, token1));\n require(address(pair) != address(0), \"JoeMakerV2: Invalid pair\");\n // balanceOf: S1 - S4: OK\n // transfer: X1 - X5: OK\n IERC20(address(pair)).safeTransfer(address(pair), pair.balanceOf(address(this)));\n\n // X1 - X5: OK\n // We don't take amount0 and amount1 from here, as it won't take into account reflect tokens.\n pair.burn(address(this));\n\n // We get the amount0 and amount1 by their respective balance of JoeMakerV2.\n uint256 amount0 = IERC20(token0).balanceOf(address(this));\n uint256 amount1 = IERC20(token1).balanceOf(address(this));\n\n emit LogConvert(msg.sender, token0, token1, amount0, amount1, _convertStep(token0, token1, amount0, amount1));\n }\n\n function _convertStep(\n address token0,\n address token1,\n uint256 amount0,\n uint256 amount1\n ) internal returns (uint256 joeOut) {\n // Interactions\n if (token0 == token1) {\n uint256 amount = amount0.add(amount1);\n if (token0 == joe) {\n IERC20(joe).safeTransfer(bar, amount);\n joeOut = amount;\n } else if (token0 == wavax) {\n joeOut = _toJOE(wavax, amount);\n } else {\n address bridge = bridgeFor(token0);\n amount = _swap(token0, bridge, amount, address(this));\n joeOut = _convertStep(bridge, bridge, amount, 0);\n }\n } else if (token0 == joe) {\n // eg. JOE - AVAX\n IERC20(joe).safeTransfer(bar, amount0);\n joeOut = _toJOE(token1, amount1).add(amount0);\n } else if (token1 == joe) {\n // eg. USDT - JOE\n IERC20(joe).safeTransfer(bar, amount1);\n joeOut = _toJOE(token0, amount0).add(amount1);\n } else if (token0 == wavax) {\n // eg. AVAX - USDC\n joeOut = _toJOE(wavax, _swap(token1, wavax, amount1, address(this)).add(amount0));\n } else if (token1 == wavax) {\n // eg. USDT - AVAX\n joeOut = _toJOE(wavax, _swap(token0, wavax, amount0, address(this)).add(amount1));\n } else {\n // eg. MIC - USDT\n address bridge0 = bridgeFor(token0);\n address bridge1 = bridgeFor(token1);\n if (bridge0 == token1) {\n // eg. MIC - USDT - and bridgeFor(MIC) = USDT\n joeOut = _convertStep(bridge0, token1, _swap(token0, bridge0, amount0, address(this)), amount1);\n } else if (bridge1 == token0) {\n // eg. WBTC - DSD - and bridgeFor(DSD) = WBTC\n joeOut = _convertStep(token0, bridge1, amount0, _swap(token1, bridge1, amount1, address(this)));\n } else {\n joeOut = _convertStep(\n bridge0,\n bridge1, // eg. USDT - DSD - and bridgeFor(DSD) = WBTC\n _swap(token0, bridge0, amount0, address(this)),\n _swap(token1, bridge1, amount1, address(this))\n );\n }\n }\n }\n\n function _swap(\n address fromToken,\n address toToken,\n uint256 amountIn,\n address to\n ) internal returns (uint256 realAmountOut) {\n // Checks\n // X1 - X5: OK\n IJoePair pair = IJoePair(factory.getPair(fromToken, toToken));\n require(address(pair) != address(0), \"JoeMakerV2: Cannot convert\");\n\n // Interactions\n // X1 - X5: OK\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n\n IERC20(fromToken).safeTransfer(address(pair), amountIn);\n\n // Added in case fromToken is a reflect token.\n if (fromToken == pair.token0()) {\n amountIn = IERC20(fromToken).balanceOf(address(pair)) - reserve0;\n } else {\n amountIn = IERC20(fromToken).balanceOf(address(pair)) - reserve1;\n }\n\n uint256 balanceBefore = IERC20(toToken).balanceOf(to);\n\n uint256 amountInWithFee = amountIn.mul(997);\n if (fromToken == pair.token0()) {\n uint256 amountOut = amountInWithFee.mul(reserve1) / reserve0.mul(1000).add(amountInWithFee);\n pair.swap(0, amountOut, to, new bytes(0));\n // TODO: Add maximum slippage?\n } else {\n uint256 amountOut = amountInWithFee.mul(reserve0) / reserve1.mul(1000).add(amountInWithFee);\n pair.swap(amountOut, 0, to, new bytes(0));\n // TODO: Add maximum slippage?\n }\n\n realAmountOut = IERC20(toToken).balanceOf(to) - balanceBefore;\n }\n\n function _toJOE(address token, uint256 amountIn) internal returns (uint256 amountOut) {\n // X1 - X5: OK\n amountOut = _swap(token, joe, amountIn, bar);\n }\n\n /* ========== RESTRICTED FUNCTIONS ========== */\n\n function setBridge(address token, address bridge) external onlyOwner {\n // Checks\n require(token != joe && token != wavax && token != bridge, \"JoeMakerV2: Invalid bridge\");\n\n // Effects\n _bridges[token] = bridge;\n emit LogBridgeSet(token, bridge);\n }\n}\n" + }, + "contracts/JoeMaker.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// P1 - P3: OK\npragma solidity 0.6.12;\nimport \"./libraries/SafeMath.sol\";\nimport \"./libraries/SafeERC20.sol\";\n\nimport \"./traderjoe/interfaces/IJoeERC20.sol\";\nimport \"./traderjoe/interfaces/IJoePair.sol\";\nimport \"./traderjoe/interfaces/IJoeFactory.sol\";\n\nimport \"./boringcrypto/BoringOwnable.sol\";\n\n// JoeMaker is MasterJoe's left hand and kinda a wizard. He can cook up Joe from pretty much anything!\n// This contract handles \"serving up\" rewards for xJoe holders by trading tokens collected from fees for Joe.\n\n// T1 - T4: OK\ncontract JoeMaker is BoringOwnable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n // V1 - V5: OK\n IJoeFactory public immutable factory;\n //0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac\n // V1 - V5: OK\n address public immutable bar;\n //0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272\n // V1 - V5: OK\n address private immutable joe;\n //0x6B3595068778DD592e39A122f4f5a5cF09C90fE2\n // V1 - V5: OK\n address private immutable wavax;\n //0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\n\n // V1 - V5: OK\n mapping(address => address) internal _bridges;\n\n // E1: OK\n event LogBridgeSet(address indexed token, address indexed bridge);\n // E1: OK\n event LogConvert(\n address indexed server,\n address indexed token0,\n address indexed token1,\n uint256 amount0,\n uint256 amount1,\n uint256 amountJOE\n );\n\n constructor(\n address _factory,\n address _bar,\n address _joe,\n address _wavax\n ) public {\n factory = IJoeFactory(_factory);\n bar = _bar;\n joe = _joe;\n wavax = _wavax;\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n function bridgeFor(address token) public view returns (address bridge) {\n bridge = _bridges[token];\n if (bridge == address(0)) {\n bridge = wavax;\n }\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n function setBridge(address token, address bridge) external onlyOwner {\n // Checks\n require(token != joe && token != wavax && token != bridge, \"JoeMaker: Invalid bridge\");\n\n // Effects\n _bridges[token] = bridge;\n emit LogBridgeSet(token, bridge);\n }\n\n // M1 - M5: OK\n // C1 - C24: OK\n // C6: It's not a fool proof solution, but it prevents flash loans, so here it's ok to use tx.origin\n modifier onlyEOA() {\n // Try to make flash-loan exploit harder to do by only allowing externally owned addresses.\n require(msg.sender == tx.origin, \"JoeMaker: must use EOA\");\n _;\n }\n\n // F1 - F10: OK\n // F3: _convert is separate to save gas by only checking the 'onlyEOA' modifier once in case of convertMultiple\n // F6: There is an exploit to add lots of JOE to the bar, run convert, then remove the JOE again.\n // As the size of the JoeBar has grown, this requires large amounts of funds and isn't super profitable anymore\n // The onlyEOA modifier prevents this being done with a flash loan.\n // C1 - C24: OK\n function convert(address token0, address token1) external onlyEOA {\n _convert(token0, token1);\n }\n\n // F1 - F10: OK, see convert\n // C1 - C24: OK\n // C3: Loop is under control of the caller\n function convertMultiple(address[] calldata token0, address[] calldata token1) external onlyEOA {\n // TODO: This can be optimized a fair bit, but this is safer and simpler for now\n uint256 len = token0.length;\n for (uint256 i = 0; i < len; i++) {\n _convert(token0[i], token1[i]);\n }\n }\n\n // F1 - F10: OK\n // C1- C24: OK\n function _convert(address token0, address token1) internal {\n // Interactions\n // S1 - S4: OK\n IJoePair pair = IJoePair(factory.getPair(token0, token1));\n require(address(pair) != address(0), \"JoeMaker: Invalid pair\");\n // balanceOf: S1 - S4: OK\n // transfer: X1 - X5: OK\n IERC20(address(pair)).safeTransfer(address(pair), pair.balanceOf(address(this)));\n // X1 - X5: OK\n (uint256 amount0, uint256 amount1) = pair.burn(address(this));\n if (token0 != pair.token0()) {\n (amount0, amount1) = (amount1, amount0);\n }\n emit LogConvert(msg.sender, token0, token1, amount0, amount1, _convertStep(token0, token1, amount0, amount1));\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n // All safeTransfer, _swap, _toJOE, _convertStep: X1 - X5: OK\n function _convertStep(\n address token0,\n address token1,\n uint256 amount0,\n uint256 amount1\n ) internal returns (uint256 joeOut) {\n // Interactions\n if (token0 == token1) {\n uint256 amount = amount0.add(amount1);\n if (token0 == joe) {\n IERC20(joe).safeTransfer(bar, amount);\n joeOut = amount;\n } else if (token0 == wavax) {\n joeOut = _toJOE(wavax, amount);\n } else {\n address bridge = bridgeFor(token0);\n amount = _swap(token0, bridge, amount, address(this));\n joeOut = _convertStep(bridge, bridge, amount, 0);\n }\n } else if (token0 == joe) {\n // eg. JOE - AVAX\n IERC20(joe).safeTransfer(bar, amount0);\n joeOut = _toJOE(token1, amount1).add(amount0);\n } else if (token1 == joe) {\n // eg. USDT - JOE\n IERC20(joe).safeTransfer(bar, amount1);\n joeOut = _toJOE(token0, amount0).add(amount1);\n } else if (token0 == wavax) {\n // eg. AVAX - USDC\n joeOut = _toJOE(wavax, _swap(token1, wavax, amount1, address(this)).add(amount0));\n } else if (token1 == wavax) {\n // eg. USDT - AVAX\n joeOut = _toJOE(wavax, _swap(token0, wavax, amount0, address(this)).add(amount1));\n } else {\n // eg. MIC - USDT\n address bridge0 = bridgeFor(token0);\n address bridge1 = bridgeFor(token1);\n if (bridge0 == token1) {\n // eg. MIC - USDT - and bridgeFor(MIC) = USDT\n joeOut = _convertStep(bridge0, token1, _swap(token0, bridge0, amount0, address(this)), amount1);\n } else if (bridge1 == token0) {\n // eg. WBTC - DSD - and bridgeFor(DSD) = WBTC\n joeOut = _convertStep(token0, bridge1, amount0, _swap(token1, bridge1, amount1, address(this)));\n } else {\n joeOut = _convertStep(\n bridge0,\n bridge1, // eg. USDT - DSD - and bridgeFor(DSD) = WBTC\n _swap(token0, bridge0, amount0, address(this)),\n _swap(token1, bridge1, amount1, address(this))\n );\n }\n }\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n // All safeTransfer, swap: X1 - X5: OK\n function _swap(\n address fromToken,\n address toToken,\n uint256 amountIn,\n address to\n ) internal returns (uint256 amountOut) {\n // Checks\n // X1 - X5: OK\n IJoePair pair = IJoePair(factory.getPair(fromToken, toToken));\n require(address(pair) != address(0), \"JoeMaker: Cannot convert\");\n\n // Interactions\n // X1 - X5: OK\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n uint256 amountInWithFee = amountIn.mul(997);\n if (fromToken == pair.token0()) {\n amountOut = amountIn.mul(997).mul(reserve1) / reserve0.mul(1000).add(amountInWithFee);\n IERC20(fromToken).safeTransfer(address(pair), amountIn);\n pair.swap(0, amountOut, to, new bytes(0));\n // TODO: Add maximum slippage?\n } else {\n amountOut = amountIn.mul(997).mul(reserve0) / reserve1.mul(1000).add(amountInWithFee);\n IERC20(fromToken).safeTransfer(address(pair), amountIn);\n pair.swap(amountOut, 0, to, new bytes(0));\n // TODO: Add maximum slippage?\n }\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n function _toJOE(address token, uint256 amountIn) internal returns (uint256 amountOut) {\n // X1 - X5: OK\n amountOut = _swap(token, joe, amountIn, bar);\n }\n}\n" + }, + "contracts/mocks/JoeMakerExploitMock.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"../JoeMaker.sol\";\n\ncontract JoeMakerExploitMock {\n JoeMaker public immutable joeMaker;\n\n constructor(address _joeMaker) public {\n joeMaker = JoeMaker(_joeMaker);\n }\n\n function convert(address token0, address token1) external {\n joeMaker.convert(token0, token1);\n }\n}\n" + }, + "contracts/TokenVesting.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.6.0;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./libraries/SafeERC20.sol\";\nimport \"./libraries/SafeMath.sol\";\n\n/**\n * @title TokenVesting\n * @dev A token holder contract that can release its token balance gradually like a\n * typical vesting scheme, with a cliff and vesting period. Optionally revocable by the\n * owner.\n */\ncontract TokenVesting is Ownable {\n // The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is\n // therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore,\n // it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a\n // cliff period of a year and a duration of four years, are safe to use.\n // solhint-disable not-rely-on-time\n\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n event TokensReleased(address token, uint256 amount);\n event TokenVestingRevoked(address token);\n\n // beneficiary of tokens after they are released\n address private _beneficiary;\n\n // Durations and timestamps are expressed in UNIX time, the same units as block.timestamp.\n uint256 private _cliff;\n uint256 private _start;\n uint256 private _duration;\n\n bool private _revocable;\n\n mapping(address => uint256) private _released;\n mapping(address => bool) private _revoked;\n\n /**\n * @dev Creates a vesting contract that vests its balance of any ERC20 token to the\n * beneficiary, gradually in a linear fashion until start + duration. By then all\n * of the balance will have vested.\n * @param beneficiary address of the beneficiary to whom vested tokens are transferred\n * @param cliffDuration duration in seconds of the cliff in which tokens will begin to vest\n * @param start the time (as Unix time) at which point vesting starts\n * @param duration duration in seconds of the period in which the tokens will vest\n * @param revocable whether the vesting is revocable or not\n */\n constructor(\n address beneficiary,\n uint256 start,\n uint256 cliffDuration,\n uint256 duration,\n bool revocable\n ) public {\n require(beneficiary != address(0), \"TokenVesting: beneficiary is the zero address\");\n // solhint-disable-next-line max-line-length\n require(cliffDuration <= duration, \"TokenVesting: cliff is longer than duration\");\n require(duration > 0, \"TokenVesting: duration is 0\");\n // solhint-disable-next-line max-line-length\n require(start.add(duration) > block.timestamp, \"TokenVesting: final time is before current time\");\n\n _beneficiary = beneficiary;\n _revocable = revocable;\n _duration = duration;\n _cliff = start.add(cliffDuration);\n _start = start;\n }\n\n /**\n * @return the beneficiary of the tokens.\n */\n function beneficiary() public view returns (address) {\n return _beneficiary;\n }\n\n /**\n * @return the cliff time of the token vesting.\n */\n function cliff() public view returns (uint256) {\n return _cliff;\n }\n\n /**\n * @return the start time of the token vesting.\n */\n function start() public view returns (uint256) {\n return _start;\n }\n\n /**\n * @return the duration of the token vesting.\n */\n function duration() public view returns (uint256) {\n return _duration;\n }\n\n /**\n * @return true if the vesting is revocable.\n */\n function revocable() public view returns (bool) {\n return _revocable;\n }\n\n /**\n * @return the amount of the token released.\n */\n function released(address token) public view returns (uint256) {\n return _released[token];\n }\n\n /**\n * @return true if the token is revoked.\n */\n function revoked(address token) public view returns (bool) {\n return _revoked[token];\n }\n\n /**\n * @notice Transfers vested tokens to beneficiary.\n * @param token ERC20 token which is being vested\n */\n function release(IERC20 token) public {\n uint256 unreleased = _releasableAmount(token);\n\n require(unreleased > 0, \"TokenVesting: no tokens are due\");\n\n _released[address(token)] = _released[address(token)].add(unreleased);\n\n token.safeTransfer(_beneficiary, unreleased);\n\n emit TokensReleased(address(token), unreleased);\n }\n\n /**\n * @notice Allows the owner to revoke the vesting. Tokens already vested\n * remain in the contract, the rest are returned to the owner.\n * @param token ERC20 token which is being vested\n */\n function revoke(IERC20 token) public onlyOwner {\n require(_revocable, \"TokenVesting: cannot revoke\");\n require(!_revoked[address(token)], \"TokenVesting: token already revoked\");\n\n uint256 balance = token.balanceOf(address(this));\n\n uint256 unreleased = _releasableAmount(token);\n uint256 refund = balance.sub(unreleased);\n\n _revoked[address(token)] = true;\n\n token.safeTransfer(owner(), refund);\n\n emit TokenVestingRevoked(address(token));\n }\n\n /**\n * @dev Calculates the amount that has already vested but hasn't been released yet.\n * @param token ERC20 token which is being vested\n */\n function _releasableAmount(IERC20 token) private view returns (uint256) {\n return _vestedAmount(token).sub(_released[address(token)]);\n }\n\n /**\n * @dev Calculates the amount that has already vested.\n * @param token ERC20 token which is being vested\n */\n function _vestedAmount(IERC20 token) private view returns (uint256) {\n uint256 currentBalance = token.balanceOf(address(this));\n uint256 totalBalance = currentBalance.add(_released[address(token)]);\n\n if (block.timestamp < _cliff) {\n return 0;\n } else if (block.timestamp >= _start.add(_duration) || _revoked[address(token)]) {\n return totalBalance;\n } else {\n return totalBalance.mul(block.timestamp.sub(_start)).div(_duration);\n }\n }\n}\n" + }, + "contracts/JoeMakerV3.sol": { + "content": "// SPDX-License-Identifier: MIT\n\n// P1 - P3: OK\npragma solidity 0.6.12;\n\nimport \"./libraries/SafeMath.sol\";\nimport \"./libraries/SafeERC20.sol\";\n\nimport \"./traderjoe/interfaces/IERC20.sol\";\nimport \"./traderjoe/interfaces/IJoePair.sol\";\nimport \"./traderjoe/interfaces/IJoeFactory.sol\";\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\n// JoeMakerV3 is MasterJoe's left hand and kinda a wizard. He can cook up Joe from pretty much anything!\n// This contract handles \"serving up\" rewards for xJoe holders by trading tokens collected from fees for Joe.\n\n// T1 - T4: OK\ncontract JoeMakerV3 is Ownable {\n using SafeMath for uint256;\n using SafeERC20 for IERC20;\n\n IJoeFactory public immutable factory;\n\n address public immutable bar;\n address private immutable joe;\n address private immutable wavax;\n uint256 public devCut = 0; // in basis points aka parts per 10,000 so 5000 is 50%, cap of 50%, default is 0\n address public devAddr;\n\n // set of addresses that can perform certain functions\n mapping(address => bool) public isAuth;\n address[] public authorized;\n bool public anyAuth = false;\n\n modifier onlyAuth() {\n require(isAuth[msg.sender] || anyAuth, \"JoeMakerV3: FORBIDDEN\");\n _;\n }\n\n // V1 - V5: OK\n mapping(address => address) internal _bridges;\n\n event SetDevAddr(address _addr);\n event SetDevCut(uint256 _amount);\n event LogBridgeSet(address indexed token, address indexed bridge);\n event LogConvert(\n address indexed server,\n address indexed token0,\n address indexed token1,\n uint256 amount0,\n uint256 amount1,\n uint256 amountJOE\n );\n\n constructor(\n address _factory,\n address _bar,\n address _joe,\n address _wavax\n ) public {\n factory = IJoeFactory(_factory);\n bar = _bar;\n joe = _joe;\n wavax = _wavax;\n devAddr = msg.sender;\n isAuth[msg.sender] = true;\n authorized.push(msg.sender);\n }\n\n // Begin Owner functions\n function addAuth(address _auth) external onlyOwner {\n isAuth[_auth] = true;\n authorized.push(_auth);\n }\n\n function revokeAuth(address _auth) external onlyOwner {\n isAuth[_auth] = false;\n }\n\n // setting anyAuth to true allows anyone to call functions protected by onlyAuth\n function setAnyAuth(bool access) external onlyOwner {\n anyAuth = access;\n }\n\n function setBridge(address token, address bridge) external onlyOwner {\n // Checks\n require(token != joe && token != wavax && token != bridge, \"JoeMakerV3: Invalid bridge\");\n\n // Effects\n _bridges[token] = bridge;\n emit LogBridgeSet(token, bridge);\n }\n\n function setDevCut(uint256 _amount) external onlyOwner {\n require(_amount <= 5000, \"setDevCut: cut too high\");\n devCut = _amount;\n\n emit SetDevCut(_amount);\n }\n\n function setDevAddr(address _addr) external onlyOwner {\n require(_addr != address(0), \"setDevAddr, address cannot be zero address\");\n devAddr = _addr;\n\n emit SetDevAddr(_addr);\n }\n\n // End owner functions\n\n function bridgeFor(address token) public view returns (address bridge) {\n bridge = _bridges[token];\n if (bridge == address(0)) {\n bridge = wavax;\n }\n }\n\n // C6: It's not a fool proof solution, but it prevents flash loans, so here it's ok to use tx.origin\n modifier onlyEOA() {\n // Try to make flash-loan exploit harder to do by only allowing externally owned addresses.\n require(msg.sender == tx.origin, \"JoeMakerV3: must use EOA\");\n _;\n }\n\n // F1 - F10: OK\n // F3: _convert is separate to save gas by only checking the 'onlyEOA' modifier once in case of convertMultiple\n // F6: There is an exploit to add lots of JOE to the bar, run convert, then remove the JOE again.\n // As the size of the JoeBar has grown, this requires large amounts of funds and isn't super profitable anymore\n // The onlyEOA modifier prevents this being done with a flash loan.\n // C1 - C24: OK\n function convert(address token0, address token1) external onlyEOA onlyAuth {\n _convert(token0, token1);\n }\n\n // F1 - F10: OK, see convert\n // C1 - C24: OK\n // C3: Loop is under control of the caller\n function convertMultiple(address[] calldata token0, address[] calldata token1) external onlyEOA onlyAuth {\n // TODO: This can be optimized a fair bit, but this is safer and simpler for now\n uint256 len = token0.length;\n for (uint256 i = 0; i < len; i++) {\n _convert(token0[i], token1[i]);\n }\n }\n\n // F1 - F10: OK\n // C1- C24: OK\n function _convert(address token0, address token1) internal {\n uint256 amount0;\n uint256 amount1;\n\n // handle case where non-LP tokens need to be converted\n if (token0 == token1) {\n amount0 = IERC20(token0).balanceOf(address(this));\n amount1 = 0;\n } else {\n IJoePair pair = IJoePair(factory.getPair(token0, token1));\n require(address(pair) != address(0), \"JoeMakerV3: Invalid pair\");\n\n IERC20(address(pair)).safeTransfer(address(pair), pair.balanceOf(address(this)));\n\n // take balance of tokens in this contract before burning the pair, incase there are already some here\n uint256 tok0bal = IERC20(token0).balanceOf(address(this));\n uint256 tok1bal = IERC20(token1).balanceOf(address(this));\n\n pair.burn(address(this));\n\n // subtract old balance of tokens from new balance\n // the return values of pair.burn cant be trusted due to transfer tax tokens\n amount0 = IERC20(token0).balanceOf(address(this)).sub(tok0bal);\n amount1 = IERC20(token1).balanceOf(address(this)).sub(tok1bal);\n }\n emit LogConvert(msg.sender, token0, token1, amount0, amount1, _convertStep(token0, token1, amount0, amount1));\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n // All safeTransfer, _swap, _toJOE, _convertStep: X1 - X5: OK\n function _convertStep(\n address token0,\n address token1,\n uint256 amount0,\n uint256 amount1\n ) internal returns (uint256 joeOut) {\n // Interactions\n if (token0 == token1) {\n uint256 amount = amount0.add(amount1);\n if (token0 == joe) {\n IERC20(joe).safeTransfer(bar, amount);\n joeOut = amount;\n } else if (token0 == wavax) {\n joeOut = _toJOE(wavax, amount);\n } else {\n address bridge = bridgeFor(token0);\n amount = _swap(token0, bridge, amount, address(this));\n joeOut = _convertStep(bridge, bridge, amount, 0);\n }\n } else if (token0 == joe) {\n // eg. JOE - AVAX\n IERC20(joe).safeTransfer(bar, amount0);\n joeOut = _toJOE(token1, amount1).add(amount0);\n } else if (token1 == joe) {\n // eg. USDT - JOE\n IERC20(joe).safeTransfer(bar, amount1);\n joeOut = _toJOE(token0, amount0).add(amount1);\n } else if (token0 == wavax) {\n // eg. AVAX - USDC\n joeOut = _toJOE(wavax, _swap(token1, wavax, amount1, address(this)).add(amount0));\n } else if (token1 == wavax) {\n // eg. USDT - AVAX\n joeOut = _toJOE(wavax, _swap(token0, wavax, amount0, address(this)).add(amount1));\n } else {\n // eg. MIC - USDT\n address bridge0 = bridgeFor(token0);\n address bridge1 = bridgeFor(token1);\n if (bridge0 == token1) {\n // eg. MIC - USDT - and bridgeFor(MIC) = USDT\n joeOut = _convertStep(bridge0, token1, _swap(token0, bridge0, amount0, address(this)), amount1);\n } else if (bridge1 == token0) {\n // eg. WBTC - DSD - and bridgeFor(DSD) = WBTC\n joeOut = _convertStep(token0, bridge1, amount0, _swap(token1, bridge1, amount1, address(this)));\n } else {\n joeOut = _convertStep(\n bridge0,\n bridge1, // eg. USDT - DSD - and bridgeFor(DSD) = WBTC\n _swap(token0, bridge0, amount0, address(this)),\n _swap(token1, bridge1, amount1, address(this))\n );\n }\n }\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n // All safeTransfer, swap: X1 - X5: OK\n function _swap(\n address fromToken,\n address toToken,\n uint256 amountIn,\n address to\n ) internal returns (uint256 amountOut) {\n // Checks\n // X1 - X5: OK\n IJoePair pair = IJoePair(factory.getPair(fromToken, toToken));\n require(address(pair) != address(0), \"JoeMakerV3: Cannot convert\");\n\n (uint256 reserve0, uint256 reserve1, ) = pair.getReserves();\n (uint256 reserveInput, uint256 reserveOutput) = fromToken == pair.token0()\n ? (reserve0, reserve1)\n : (reserve1, reserve0);\n IERC20(fromToken).safeTransfer(address(pair), amountIn);\n uint256 amountInput = IERC20(fromToken).balanceOf(address(pair)).sub(reserveInput); // calculate amount that was transferred, this accounts for transfer taxes\n\n amountOut = getAmountOut(amountInput, reserveInput, reserveOutput);\n (uint256 amount0Out, uint256 amount1Out) = fromToken == pair.token0()\n ? (uint256(0), amountOut)\n : (amountOut, uint256(0));\n pair.swap(amount0Out, amount1Out, to, new bytes(0));\n }\n\n // F1 - F10: OK\n // C1 - C24: OK\n function _toJOE(address token, uint256 amountIn) internal returns (uint256 amountOut) {\n uint256 amount = amountIn;\n if (devCut > 0) {\n amount = amount.mul(devCut).div(10000);\n IERC20(token).safeTransfer(devAddr, amount);\n amount = amountIn.sub(amount);\n }\n amountOut = _swap(token, joe, amount, bar);\n }\n\n function getAmountOut(\n uint256 amountIn,\n uint256 reserveIn,\n uint256 reserveOut\n ) internal pure returns (uint256 amountOut) {\n require(amountIn > 0, \"JoeMakerV3: INSUFFICIENT_INPUT_AMOUNT\");\n require(reserveIn > 0 && reserveOut > 0, \"JoeMakerV3: INSUFFICIENT_LIQUIDITY\");\n uint256 amountInWithFee = amountIn.mul(997);\n uint256 numerator = amountInWithFee.mul(reserveOut);\n uint256 denominator = reserveIn.mul(1000).add(amountInWithFee);\n amountOut = numerator / denominator;\n }\n}\n" + }, + "contracts/JoeBar.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\n\n// JoeBar is the coolest bar in town. You come in with some Joe, and leave with more! The longer you stay, the more Joe you get.\n//\n// This contract handles swapping to and from xJoe, JoeSwap's staking token.\ncontract JoeBar is ERC20(\"JoeBar\", \"xJOE\") {\n using SafeMath for uint256;\n IERC20 public joe;\n\n // Define the Joe token contract\n constructor(IERC20 _joe) public {\n joe = _joe;\n }\n\n // Enter the bar. Pay some JOEs. Earn some shares.\n // Locks Joe and mints xJoe\n function enter(uint256 _amount) public {\n // Gets the amount of Joe locked in the contract\n uint256 totalJoe = joe.balanceOf(address(this));\n // Gets the amount of xJoe in existence\n uint256 totalShares = totalSupply();\n // If no xJoe exists, mint it 1:1 to the amount put in\n if (totalShares == 0 || totalJoe == 0) {\n _mint(msg.sender, _amount);\n }\n // Calculate and mint the amount of xJoe the Joe is worth. The ratio will change overtime, as xJoe is burned/minted and Joe deposited + gained from fees / withdrawn.\n else {\n uint256 what = _amount.mul(totalShares).div(totalJoe);\n _mint(msg.sender, what);\n }\n // Lock the Joe in the contract\n joe.transferFrom(msg.sender, address(this), _amount);\n }\n\n // Leave the bar. Claim back your JOEs.\n // Unlocks the staked + gained Joe and burns xJoe\n function leave(uint256 _share) public {\n // Gets the amount of xJoe in existence\n uint256 totalShares = totalSupply();\n // Calculates the amount of Joe the xJoe is worth\n uint256 what = _share.mul(joe.balanceOf(address(this))).div(totalShares);\n _burn(msg.sender, _share);\n joe.transfer(msg.sender, what);\n }\n}\n" + }, + "contracts/interfaces/IMasterChef.sol": { + "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\nimport \"../libraries/BoringERC20.sol\";\n\ninterface IMasterChef {\n using BoringERC20 for IERC20;\n struct UserInfo {\n uint256 amount; // How many LP tokens the user has provided.\n uint256 rewardDebt; // Reward debt. See explanation below.\n }\n\n struct PoolInfo {\n IERC20 lpToken; // Address of LP token contract.\n uint256 allocPoint; // How many allocation points assigned to this pool. JOE to distribute per block.\n uint256 lastRewardTimestamp; // Last block number that JOE distribution occurs.\n uint256 accJoePerShare; // Accumulated JOE per share, times 1e12. See below.\n }\n\n function poolInfo(uint256 pid) external view returns (IMasterChef.PoolInfo memory);\n\n function totalAllocPoint() external view returns (uint256);\n\n function deposit(uint256 _pid, uint256 _amount) external;\n\n function devPercent() external view returns (uint256);\n\n function treasuryPercent() external view returns (uint256);\n\n function investorPercent() external view returns (uint256);\n}\n" + }, + "contracts/JoeHatToken.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.6.2;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol\";\n\ncontract JoeHatToken is ERC20Burnable {\n /**\n * @dev Mints `initialSupply` amount of token and transfers them to `owner`.\n *\n * See {ERC20-constructor}.\n */\n constructor(address owner) public ERC20(\"Joe Hat Token\", \"HAT\") {\n uint256 initialSupply = 150e18;\n _mint(owner, initialSupply);\n }\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../../utils/Context.sol\";\nimport \"./ERC20.sol\";\n\n/**\n * @dev Extension of {ERC20} that allows token holders to destroy both their own\n * tokens and those that they have an allowance for, in a way that can be\n * recognized off-chain (via event analysis).\n */\nabstract contract ERC20Burnable is Context, ERC20 {\n using SafeMath for uint256;\n\n /**\n * @dev Destroys `amount` tokens from the caller.\n *\n * See {ERC20-_burn}.\n */\n function burn(uint256 amount) public virtual {\n _burn(_msgSender(), amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, deducting from the caller's\n * allowance.\n *\n * See {ERC20-_burn} and {ERC20-allowance}.\n *\n * Requirements:\n *\n * - the caller must have allowance for ``accounts``'s tokens of at least\n * `amount`.\n */\n function burnFrom(address account, uint256 amount) public virtual {\n uint256 decreasedAllowance = allowance(account, _msgSender()).sub(amount, \"ERC20: burn amount exceeds allowance\");\n\n _approve(account, _msgSender(), decreasedAllowance);\n _burn(account, amount);\n }\n}\n" + }, + "contracts/traderjoe/JoeFactory.sol": { + "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity =0.6.12;\n\nimport \"./interfaces/IJoeFactory.sol\";\nimport \"./JoePair.sol\";\n\ncontract JoeFactory is IJoeFactory {\n address public override feeTo;\n address public override feeToSetter;\n address public override migrator;\n\n mapping(address => mapping(address => address)) public override getPair;\n address[] public override allPairs;\n\n event PairCreated(address indexed token0, address indexed token1, address pair, uint256);\n\n constructor(address _feeToSetter) public {\n feeToSetter = _feeToSetter;\n }\n\n function allPairsLength() external view override returns (uint256) {\n return allPairs.length;\n }\n\n function pairCodeHash() external pure returns (bytes32) {\n return keccak256(type(JoePair).creationCode);\n }\n\n function createPair(address tokenA, address tokenB) external override returns (address pair) {\n require(tokenA != tokenB, \"Joe: IDENTICAL_ADDRESSES\");\n (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);\n require(token0 != address(0), \"Joe: ZERO_ADDRESS\");\n require(getPair[token0][token1] == address(0), \"Joe: PAIR_EXISTS\"); // single check is sufficient\n bytes memory bytecode = type(JoePair).creationCode;\n bytes32 salt = keccak256(abi.encodePacked(token0, token1));\n assembly {\n pair := create2(0, add(bytecode, 32), mload(bytecode), salt)\n }\n JoePair(pair).initialize(token0, token1);\n getPair[token0][token1] = pair;\n getPair[token1][token0] = pair; // populate mapping in the reverse direction\n allPairs.push(pair);\n emit PairCreated(token0, token1, pair, allPairs.length);\n }\n\n function setFeeTo(address _feeTo) external override {\n require(msg.sender == feeToSetter, \"Joe: FORBIDDEN\");\n feeTo = _feeTo;\n }\n\n function setMigrator(address _migrator) external override {\n require(msg.sender == feeToSetter, \"Joe: FORBIDDEN\");\n migrator = _migrator;\n }\n\n function setFeeToSetter(address _feeToSetter) external override {\n require(msg.sender == feeToSetter, \"Joe: FORBIDDEN\");\n feeToSetter = _feeToSetter;\n }\n}\n" + } + }, + "settings": { + "optimizer": { + "enabled": true, + "runs": 200 + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata", + "devdoc", + "userdoc", + "storageLayout", + "evm.gasEstimates" + ], + "": [ + "ast" + ] + } + }, + "metadata": { + "useLiteralContent": true + }, + "libraries": { + "": { + "__CACHE_BREAKER__": "0x00000000d41867734bbee4c6863d9255b2b06ac1" + } + } + } +} \ No newline at end of file