Contract 0x155482Bd4e5128082D61a2384935D4BBDcb0E7a7

Txn Hash Method
Block
From
To
Value [Txn Fee]
0x3c9a94ca6236578a69dd955a8fbda284cf58a06358fc702feebdd8dbd1d665a0Harvest395861172022-06-02 3:01:0927 days 13 hrs ago0xc0ba637e161c01079b69be19ffa7cd1643fc4905 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.003092492178
0x7af8b6b0938922c7693e78d37a2266bafd24f60a209027859050e6fda2546ba0Harvest392177112022-05-28 3:10:3932 days 13 hrs ago0x4498547b4f0bc7d10ea08471a44e14fd04f72099 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.007689108727
0x8c379c4d96d438bfa4d4099b1627ed7133f3a80a9eebebd18ddb19ee6db63478Withdraw387178962022-05-21 7:36:4239 days 9 hrs ago0x11c74ea53003c8b495c76c8ce625b9680bcdb2e0 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.006183843104
0xb4754db46d9ef3a315e49556e608a10d701088bf7419bca90b501a8de1272de4Set Reward Per S...378521622022-05-08 18:25:1151 days 22 hrs agoCoffin Finance: Deployer IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.073571125744
0xe1211a91e80826b7cbd307d256df76a73e3de82008d9c6ffc578f8b9d9b2132fWithdraw376802382022-05-06 10:41:3554 days 5 hrs ago0x3ecaec1c530e30bfbfa9d25fcd78111591db0f64 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.030528704206
0x36f09622fefb8b91e2ee2622f6556eceffcd8699c8c2df38bbb29a5cba10df80Harvest376801512022-05-06 10:39:2054 days 5 hrs ago0x3ecaec1c530e30bfbfa9d25fcd78111591db0f64 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.038401406134
0x3591c359d00395f3c50998b55efc941ee5ee85a841e1cb67b3d45aa3e6e97004Harvest373785222022-05-02 7:41:4058 days 8 hrs ago0xeeb38f33da298e2e470207a9c7be97430005f7c2 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.064662691963
0x9ed71bc83256fe9cf457b36974efa75c859d2b32d80c91f6f1cac198ca36f0faWithdraw373062812022-05-01 3:08:5359 days 13 hrs ago0xc5e569ded374c71d455a7475b9b7bfad5fcc9430 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.105545639462
0x78d6f60f49f5384dfa6e39f678bb1a21b3b5d0ceced01c7e46b98f59ca3d709fHarvest373047312022-05-01 2:21:3459 days 14 hrs ago0xc5e569ded374c71d455a7475b9b7bfad5fcc9430 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.140524642795
0x603f47518de59d5bed02d0405ff6bbd25e2019340d7574155e1a07b5c5b3c118Withdraw372624232022-04-30 6:35:3760 days 10 hrs ago0x6ed04d8a43e98fb7ea329722c9d3db15690fc494 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.037168712903
0x2882610a84d3bd893777cbcac4537314ed3577ba41e066b400791513642644d9Withdraw372624102022-04-30 6:35:2360 days 10 hrs ago0x6ed04d8a43e98fb7ea329722c9d3db15690fc494 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.03717404854
0x87fbb6736ae2402f6e967b16efe1c8b15752be8b7bb23f029586b8fd8523a908Harvest371099892022-04-28 0:54:1662 days 15 hrs ago0xe41fcbfa49baf65a4f11827186141e96b4b0793c IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.023233245448
0x33d133e42f15eb70e62e1cb077bce6bd55a6771b2fa628696ee0d3d36d8f52a6Harvest371099802022-04-28 0:54:0662 days 15 hrs ago0xe41fcbfa49baf65a4f11827186141e96b4b0793c IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.033208398772
0xee84ca42b904589cedf2b55db7566ed51eb68bcfa3283de58c48e475a5acd26dWithdraw371099582022-04-28 0:53:4162 days 15 hrs ago0xe41fcbfa49baf65a4f11827186141e96b4b0793c IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.022899870901
0xf9460aca14b0d1594ac34c0b26d55f294492f13916521fe2d37480249d435bb6Withdraw371099102022-04-28 0:52:5562 days 15 hrs ago0xe41fcbfa49baf65a4f11827186141e96b4b0793c IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.027754818814
0xfae405e7905fb9a11a16fa006e1f812567181201aa5a775d9763a4b964adf06bHarvest357675332022-04-11 3:55:3979 days 12 hrs ago0xcd1386e63e7fd1326651b8e1eb7b119cc443d470 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.032991930071
0x189344ca99ce622d4cd14abcc73c3cead0d0532ae460e3f4c3eb60ddd9bc34efWithdraw357675222022-04-11 3:55:2979 days 12 hrs ago0xcd1386e63e7fd1326651b8e1eb7b119cc443d470 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.027886085327
0xa9b120661ed5957c77b6f624e1c4909f21706f36b2d6b4dd5d3cefc944df990cWithdraw356696292022-04-09 23:34:5280 days 17 hrs ago0x86ddcc759d228f93b9289582cfbca3bc2ca232fc IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.022522669577
0x03c801c4f7f62dea9430c40722546b2cbb394df5ee49c36847f8e2cd6ea2a3c5Harvest356695422022-04-09 23:33:1980 days 17 hrs ago0x86ddcc759d228f93b9289582cfbca3bc2ca232fc IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.027386727838
0x67c4e52820212af0ebe4140ed198d4986c6b34073ee40ab804c28ab349f6ffe0Withdraw354861352022-04-07 19:49:0982 days 20 hrs ago0x0567d1b8f96bb13dc859927fcdc2b22349f08d54 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.028181206864
0xaf5da3b3b285a99fd07f713bb89bfea2e2c7336072de981c5ecefd9a9a34b3ebWithdraw354860422022-04-07 19:47:3482 days 20 hrs ago0x0567d1b8f96bb13dc859927fcdc2b22349f08d54 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.016744594951
0x74aaa0685a6dae6c3d7a04a0238c3e8edffee4f88257e37932878f657678787dHarvest354860342022-04-07 19:47:2682 days 20 hrs ago0x0567d1b8f96bb13dc859927fcdc2b22349f08d54 IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.041233425174
0x09ac05f4ca55e656b2ae766e3f59f6b6e7d4405214ee4d5ac4e1609342c89a69Harvest349749972022-04-01 16:36:3089 days 1 min ago0xc15c26c808f0081fd1152129becf9e88f64a454e IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.062377258503
0xa02543dc8f2ba047e60d3f5dcf99b819ada284d7a114cb0269e7d5585aeb5db8Harvest347173632022-03-29 15:33:3392 days 1 hr ago0x2cb84580f0efea27ebd322b10216cfce7bc173db IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.05920138243
0xcfce60bda86e54ff736c42f3dced29d922c063295481df458963ea3bd4738fffWithdraw347173422022-03-29 15:33:1692 days 1 hr ago0x2cb84580f0efea27ebd322b10216cfce7bc173db IN  0x155482bd4e5128082d61a2384935d4bbdcb0e7a70 FTM0.046020597311
[ Download CSV Export 
Latest 1 internal transaction
Parent Txn Hash Block From To Value
0xe04ab15da66dad6b63a121d2839e07ef133bf76b5d6a1297a6447b653c4e3c5a192178112021-10-16 4:54:26256 days 11 hrs ago Coffin Finance: Deployer  Contract Creation0 FTM
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CoffinMaker

Compiler Version
v0.8.7+commit.e28d00a7

Optimization Enabled:
Yes with 500 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 24 : CoffinMaker.sol
pragma solidity ^0.8.7;
// SPDX-License-Identifier: MIT

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

import "./Coffin.sol";

// MasterChef

contract CoffinMaker is Ownable, ReentrancyGuard {
    using SafeERC20 for IERC20;
    using SafeMath for uint256;

    struct UserInfo {
        uint256 amount; // How many LP tokens the user has provided.
        int256 rewardDebt; // it's int256, not uint256. 
        uint256 nextHarvestUntil; // When can the user harvest again.
        uint256 depositTimerStart; // deposit starting timer for withdraw lockup
    }
    // Info of each pool.
    struct PoolInfo {
        IERC20 lpToken; // Address of LP token contract.
        uint256 allocPoint; // How many allocation points assigned to this pool. COFFINs to distribute per second.
        uint256 lastRewardTime;
        uint256 accRewardPerShare; // Accumulated COFFINs per share, times 1e12.
        uint256 harvestInterval; // Harvest interval in seconds
        uint256 withdrawLockupTime; // withdraw lockup time
    }
    // The reward TOKEN
    Coffin public rewardToken;
    // Dev's address 
    address public dev_fund;
    // Marketing fund address 
    address public marketing_fund;
    // address public comaddr;
    uint256 private constant ACC_REWARD_PRECISION = 1e12;

    // Max harvest interval: 14 days.
    uint256 public constant MAXIMUM_HARVEST_INTERVAL = 1 days;
    // Max lockup interval: 14 days.
    uint256 public constant MAXIMUM_LOCKUP_INTERVAL = 14 days;

    // address public fund;
    // Info of each pool.
    PoolInfo[] public poolInfo;
    // Info of each user that stakes LP tokens.
    mapping(address => bool) public poolExistence;

    mapping(uint256 => mapping(address => UserInfo)) public userInfo;
    // Total allocation poitns. Must be the sum of all allocation points in all pools.
    uint256 public totalAllocPoint = 0;
    // The block timestamp when reward mining starts.
    uint256 public startTime;
    uint256 public endTime;
    
    // reward tokens created per second.
    uint256 public rewardPerSecond;
    uint256 public totalMintedReward;
    uint256 public constant STARTING_WITHIN = 30 days;
    uint256 public DEFAULT_VESTING_DRATION = 1095 days ; // 365 * 3 
    uint256 public TOTAL_SUPPLY = 100_000_000 ether; // 100 million.

    constructor() {}


    function init(address _rewardToken, uint256 _startTime, uint256 _rewardPerSecond) external virtual onlyOwner  {
        require (startTime==0, "only one time.");
        require (_rewardToken != address(0),"reward token address error") ;
        
        rewardToken = Coffin(_rewardToken);
        
        startTime = block.timestamp;
        if (_startTime!=0) {
            require(_startTime > block.timestamp, "CoffinMaker: The start time must be in the future. ");
            require(_startTime - block.timestamp <= STARTING_WITHIN, "CoffinMaker: invalid starting time ");
            startTime = _startTime;
        }
        rewardPerSecond = _rewardPerSecond;
        if (_rewardPerSecond==0) {
            // rewardPerSecond = totalReward / vestingDuration;
            rewardPerSecond = 1 ether;
        }
        totalMintedReward = totalMintedReward.add(rewardToken.genesis_supply());
    }

    function poolLength() external view returns (uint256) {
        return poolInfo.length;
    }


    modifier nonDuplicated(address _lpToken) {
        require(poolExistence[address(_lpToken)] == false, "CoffinMaker: duplicated");
        require(_lpToken!=address(rewardToken), "CoffinMaker: cannot use reward token as lpToken");

        uint256 length = poolInfo.length;
        for (uint256 pid = 0; pid < length; ++pid) {
            require(address(poolInfo[pid].lpToken) != _lpToken, "CoffinMaker: duplicated");
        }
        _;
    }

    function setStartTime(uint _startTime) external onlyOwner {
        require(startTime<block.timestamp, "already started");
        startTime = _startTime;
    }


    function addPool(
        uint256 _allocPoint,
        address _lpToken,
        uint256 _harvestInterval,
        uint256 _withdrawLockupTime,
        bool withUpdateAllPool
    ) public onlyOwner nonDuplicated(_lpToken) {
        require(startTime!=0, 'not initilized yet');
        if (withUpdateAllPool) {
            // basically should update everytime, except for starting. 
            _updateAllPools();
        }

        require(_harvestInterval <= MAXIMUM_HARVEST_INTERVAL, "CoffinMaker: invalid harvest interval");
        require(_withdrawLockupTime <= MAXIMUM_LOCKUP_INTERVAL, "CoffinMaker: invalid lockup interval");

        totalAllocPoint += _allocPoint;
        poolExistence[_lpToken] = true;
        uint256 _lastRewardTime = block.timestamp > startTime ? block.timestamp : startTime;
        //uint256 _lastRewardTime = block.timestamp;

        poolInfo.push(
            PoolInfo({
                lpToken: IERC20(_lpToken),
                allocPoint: _allocPoint,
                lastRewardTime: _lastRewardTime,
                // lastRewardTime: block.timestamp,
                accRewardPerShare: 0,
                harvestInterval: _harvestInterval,
                withdrawLockupTime: _withdrawLockupTime
            })
        );
    }

    // Update the given pool's reward allocation point. Can only be called by the owner.
    function setPool(
        uint256 _pid,
        uint256 _allocPoint,
        uint256 _harvestInterval,
        uint256 _withdrawLockupTime
    ) public onlyOwner {
        // check
        require(startTime!=0, 'not initilized yet');
        require(_harvestInterval <= MAXIMUM_HARVEST_INTERVAL, "CoffinMaker: invalid harvest interval");
        require(_withdrawLockupTime <= MAXIMUM_LOCKUP_INTERVAL, "CoffinMaker: invalid lockup interval");
        _updateAllPools();

        totalAllocPoint = totalAllocPoint - poolInfo[_pid].allocPoint + _allocPoint;
        poolInfo[_pid].allocPoint = _allocPoint;
        poolInfo[_pid].harvestInterval = _harvestInterval;
        poolInfo[_pid].withdrawLockupTime = _withdrawLockupTime;

        
    }



    // View function to see pending reward tokens on frontend.
    function pendingReward(uint256 _pid, address _user) external view returns (uint256) {
        require(startTime!=0, 'not initilized yet');
        if (block.timestamp<startTime) {
            return uint256(0);
        }
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][_user];
        uint256 accRewardPerShare = pool.accRewardPerShare;
        uint256 lpSupply = pool.lpToken.balanceOf(address(this));

        if (block.timestamp > pool.lastRewardTime && lpSupply != 0) {
            uint256 delta = block.timestamp - pool.lastRewardTime;
            uint256 addedReward = (delta.mul(rewardPerSecond).mul(pool.allocPoint)).div(totalAllocPoint);
            accRewardPerShare += (addedReward.mul(ACC_REWARD_PRECISION)).div(lpSupply);
        }

        return uint256(int256((user.amount.mul(accRewardPerShare)).div(ACC_REWARD_PRECISION)) - (user.rewardDebt));
    }

    // View function to see if user can harvest .
    function canHarvest(uint256 _pid, address _user) public view returns (bool) {
        require(startTime!=0, 'not initilized yet');
        UserInfo storage user = userInfo[_pid][_user];
        return block.timestamp >= user.nextHarvestUntil;
    }

    function canWithdraw(uint256 _pid, address _user) external view returns (bool) {
        require(startTime!=0, 'not initilized yet');
        UserInfo storage user = userInfo[_pid][_user];
        PoolInfo storage pool = poolInfo[_pid];
        return (user.depositTimerStart + pool.withdrawLockupTime) <= block.timestamp;
    }

    function updatePools(uint256[] calldata pids) external {
        // require(startTime!=0, 'not initilized yet');
        uint256 len = pids.length;
        for (uint256 i = 0; i < len; ++i) {
            updatePool(pids[i]);
        }
    }
    // Update reward variables for all pools. Be careful of gas spending!
    function massUpdatePools() external {
        _updateAllPools();
    }

    function _updateAllPools() internal {
        uint256 len = poolInfo.length;
        for (uint256 i = 0; i < len; i++) {
            updatePool(i);
        }
    }

    // Update reward variables of the given pool to be up-to-date.
    function updatePool(uint256 _pid) public returns (PoolInfo memory pool) {
        require(startTime!=0, 'not initilized yet');
        pool = poolInfo[_pid];
        require(pool.allocPoint>0 , "cannot update this pool for now");

        if (totalMintedReward < TOTAL_SUPPLY) {
                
            if (block.timestamp > pool.lastRewardTime) {
                uint256 lpSupply = pool.lpToken.balanceOf(address(this));
                if (lpSupply > 0) {
                    int256 delta = int256(block.timestamp - pool.lastRewardTime);
                    uint256 reward = (uint256(delta).mul(rewardPerSecond).mul(pool.allocPoint)) / totalAllocPoint;
                
                    if (totalMintedReward + reward > TOTAL_SUPPLY) {

                        reward = TOTAL_SUPPLY - totalMintedReward;
                    }
                    


                    pool.accRewardPerShare += (reward.mul( ACC_REWARD_PRECISION)) / lpSupply;
                    
                    uint256 devreward = 0;
                    uint256 marketing_amount = 0;
                    
                    // 
                    if (dev_fund!=address(0)) {
                        // ( 100 % total - 3 % initial ) / 97 * 12 => 12 % 
                        devreward = reward.div(97).mul(12);
                        //
                        rewardToken.reward_mint(dev_fund, devreward);
                        // rewardToken.pool_mint(dev_fund, devreward);
                        
                    }
                    if (marketing_fund!=address(0)) {
                        // ( 100 % total - 3 % initial ) / 97 * 8 => 8 % 
                        marketing_amount = reward.div(97).mul(8);
                        rewardToken.reward_mint(marketing_fund, marketing_amount);
                        // rewardToken.pool_mint(marketing_fund, marketing_amount);
                    }
                    rewardToken.reward_mint(address(this), reward.sub(devreward).sub(marketing_amount) );
                    // rewardToken.pool_mint(address(this), reward.sub(devreward).sub(marketing_amount) );
                    // totalMintedReward += totalMintedReward.add(reward);
                    totalMintedReward = totalMintedReward.add(reward);
                }
                pool.lastRewardTime = block.timestamp;
                poolInfo[_pid] = pool;
            }
        }

    }
    function poolTokenBalance(uint256 _pid) view public returns(uint256){
        PoolInfo storage pool = poolInfo[_pid];
        return pool.lpToken.balanceOf(msg.sender);
    }


    // Deposit LP tokens to CoffinMaker for reward token allocation.
    function deposit(
        uint256 _pid,
        uint256 _amount,
        address _to
    ) public nonReentrant {
        // check
        require(startTime!=0, 'not initilized yet');
        require(_amount > 0, "deposit should be more than 0");
        PoolInfo memory pool = updatePool(_pid);
        UserInfo storage user = userInfo[_pid][_to];
        require (_pid < poolInfo.length, "no exist");
        require(pool.allocPoint>0 , "cannot deposit this token for now");
        require(pool.lpToken.balanceOf(msg.sender)>= _amount , "you don't have enough balance in your wallet.");
        
        // effect
        if(_to==msg.sender||user.amount==0) {
            user.nextHarvestUntil = block.timestamp + pool.harvestInterval;
            user.depositTimerStart = block.timestamp;
        }
        // check balance before transfer. 
        uint256 bal1 = pool.lpToken.balanceOf(address(this));

        pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
        
        // check balance after transfer. 
        uint256 bal2 = pool.lpToken.balanceOf(address(this));

        // check the diff , it's income value. 
        uint256 actual_amount = bal2-bal1;
        
        require(actual_amount<=_amount, " income value should be smaller than argument value. " );

        user.amount += actual_amount;
        user.rewardDebt += int256((actual_amount.mul( pool.accRewardPerShare)).div( ACC_REWARD_PRECISION));

        emit EventDeposit(msg.sender, _pid, _amount, _to);
    }


    function withdrawLockup(uint256 pid) view public returns(uint256) {
        PoolInfo storage pool = poolInfo[pid];
        UserInfo storage user = userInfo[pid][msg.sender];
        return user.depositTimerStart.add(pool.withdrawLockupTime).sub(block.timestamp);
    }
    // Withdraw LP tokens from CoffinMaker.
    function withdraw(
        uint256 _pid,
        uint256 _amount,
        address _to
    ) public nonReentrant {
        require(startTime!=0, 'not initilized yet');
        require(_to != address(0), "cannot withdraw to zero address");

        PoolInfo memory pool = updatePool(_pid);
        UserInfo storage user = userInfo[_pid][msg.sender];
        // check
        require(user.amount >= _amount, "CoffinMaker: withdraw request greater than staked amount");
        require(_amount > 0, "CoffinMaker: withdraw amount should be more than 0");
        require(
            (user.depositTimerStart + pool.withdrawLockupTime) <= block.timestamp,
            "CoffinMaker: still in withdraw lockup time"
        );
        uint256 bal1 = pool.lpToken.balanceOf(address(this));

        //effect
        user.rewardDebt -= int256((_amount.mul( pool.accRewardPerShare)) .div( ACC_REWARD_PRECISION));
        user.amount -= _amount;

        //interaction
        pool.lpToken.safeTransfer(_to, _amount);

        uint256 bal2 = pool.lpToken.balanceOf(address(this));
        assert((bal1 - bal2) == _amount);

        emit EventWithdraw(msg.sender, _pid, _amount, _to);
    }

    // Withdraw without caring about rewards. EMERGENCY ONLY.
    function emergencyWithdraw(uint256 _pid) public nonReentrant {
        require(startTime!=0, 'not initilized yet');
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        // effect
        uint256 amount = user.amount;
        user.amount = 0;
        user.rewardDebt = 0;
        user.nextHarvestUntil = 0;
        user.depositTimerStart = 0;
        // interaction
        pool.lpToken.safeTransfer(address(msg.sender), amount);
        emit EmergencyWithdraw(msg.sender, _pid, amount);
    }


    function harvest(uint256 _pid, address _to) public nonReentrant {
        // require(startTime!=0, 'not initilized yet');
        require(_to != address(0), "cannot withdraw to zero address");
        PoolInfo memory pool = updatePool(_pid);
        UserInfo storage user = userInfo[_pid][msg.sender];
        require(block.timestamp >= user.nextHarvestUntil, "CoffinMaker: need to wait for next harvest time");

        int256 accumulatedReward = int256((user.amount.mul(pool.accRewardPerShare)) .div( ACC_REWARD_PRECISION));
        uint256 pending = uint256(accumulatedReward - user.rewardDebt);
        require(pending > 0, "CoffinMaker: no pending reward ");

        // Effects
        user.rewardDebt = accumulatedReward;
        user.nextHarvestUntil = block.timestamp + pool.harvestInterval;
        // Interactions
        safeRewardTransfer(_to, pending);
        emit EventHarvest(msg.sender, _pid, pending, _to);
    }



    // Safe reward transfer function, just in case if rounding error causes pool to not have enough rewards.
    function safeRewardTransfer(address _to, uint256 _amount) internal {
        require(startTime!=0, 'not initilized yet');
        uint256 bal = rewardToken.balanceOf(address(this));
        if (bal > 0) {
            if (_amount > bal) {
                IERC20(rewardToken).safeTransfer(_to, bal);
                emit EventSafeRewardTransfer(_to, bal);
            } else {
                IERC20(rewardToken).safeTransfer(_to, _amount);
                emit EventSafeRewardTransfer(_to, _amount);
            }
        }
    }

    function setRewardPerSecond(uint256 _rewardPerSecond) external onlyOwner {
        require(startTime!=0, 'not initilized yet');
        _updateAllPools();
        rewardPerSecond = _rewardPerSecond;
    }
    function setDevFund(address _dev_fund) public {
        require(msg.sender==owner() || msg.sender == dev_fund, "CoffinMaker: only from dev");
        dev_fund = _dev_fund;
        emit EventSetDev( _dev_fund);
    }
    function setMarketingFund(address _marketing_fund) public {
        require(msg.sender==owner() || msg.sender == _marketing_fund, "CoffinMaker: only from dev");
        marketing_fund = _marketing_fund;
        emit EventSetMarketingFund( _marketing_fund);
    }
    
    
    event EventSetDev(address indexed dev_fund);
    event EventSetMarketingFund(address indexed _marketing_fund);
    event EventHarvest(address indexed user, uint256 indexed pid, uint256 amount, address _to);
    
    event EventDeposit(address indexed user, uint256 indexed pid, uint256 amount, address to);
    event EventWithdraw(address indexed user, uint256 indexed pid, uint256 amount, address to);
    event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);
    
    event EventSafeRewardTransfer(address indexed to, uint256 amount);
}

File 2 of 24 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

File 3 of 24 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 4 of 24 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

File 5 of 24 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _setOwner(_msgSender());
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _setOwner(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _setOwner(newOwner);
    }

    function _setOwner(address newOwner) private {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 6 of 24 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

File 7 of 24 : Coffin.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import "./TaxableToken.sol";

contract Coffin is TaxableToken, Initializable {
    using SafeMath for uint256;
    uint256 public constant genesis_supply = 3_000_000 ether; // for initial liquidity. 
    // 
    uint256 public constant REWARD_ALLOCATION = 97_000_000 ether; // 
    uint256 public rewardClaimed;
    function init(
        address _maker
    ) external initializer onlyOwner {
        coffin_pools[_maker] = true;
        coffin_pools_array.push(_maker);

        // coffin_pools[msg.sender] = true;
        // coffin_pools_array.push(msg.sender);
        
        _mint(msg.sender, genesis_supply);
    }

    function reward_mint(address recipient, uint256 amount) public onlyPools {
        require(amount > 0, "invalidAmount");
        require(recipient != address(0), "!rewardController");
        uint256 _remainingRewards = REWARD_ALLOCATION - rewardClaimed;
        require(amount <= _remainingRewards, "exceedRewards");
        rewardClaimed = rewardClaimed + amount;
        super._mint(recipient, amount);
        emit Minted(msg.sender, recipient, amount);
    }
    
    // constructor() TaxableToken("TestToken", "testSHARE") {}
    constructor() TaxableToken("CoffinToken", "COFFIN") {}

    event MaxTotalSupplyUpdated(uint256 _newCap);
}

File 8 of 24 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) private pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 9 of 24 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 10 of 24 : Initializable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        require(_initializing || !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }
}

File 11 of 24 : TaxableToken.sol
// SPDX-License-Identifier: MIT
// coffin finance
pragma solidity ^0.8.7;
// pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./CoffinOracle.sol";
import "./PoolToken.sol";
import "./libs/Babylonian.sol";
import './interfaces/ITaxableTokenPolicy.sol';

contract TaxableToken is PoolToken {
    using SafeMath for uint256;
    address public coffinOracle;
    // fixed tax rate
    uint16 public staticTaxRate = 0;
    // latest tax rate
    uint16 public latestTaxRate = 0;
    // Address of the Tax Office
    address public taxOffice;
    // Address of the tax collector wallet
    address public taxCollectorAddress;
    // Tax Policy
    address public policy; 
    // 
    bool public using_twap;
    // Dollar Price threshold below which taxes will get burned
    uint256 public burnThreshold = 0.98e18;
    uint256 public taxThreshold = 1e18;
    //
    bool public taxActivated = false;
    bool public autoCalculateTax = false;
    address public constant BURN_ADDRESS = 0x000000000000000000000000000000000000dEaD;

    uint16 public maxTaxRate = 2000;

    // basis tax rate. 0.05% by default.
    // believe it should be bigger than flashloan fee.
    //  C.R.E.A.M => 0.03% , AAVE => 0.09%.
    uint16 public basisTaxRate = 5;
    uint32 public adjustTaxRateA = 2000000;
    uint32 public adjustTaxRateB = 4;

    mapping(address => bool) private _isExcluded;
    address[] private _excluded;

    // modifier
    modifier onlyOwnerOrTaxOffice() {
        require(
            owner() == msg.sender || taxOffice == msg.sender,
            "Caller is not the owner or the tax office"
        );
        _;
    }

    // constructor
    constructor(string memory _name, string memory _symbol)
        PoolToken(_name, _symbol)
    {}

    // internal

    // get current coUSD price
    function _getCoUSDPrice() public view returns (uint256 _price) {
        if (using_twap) {
            (uint256 __price, uint8 __d) = ICoffinOracle(coffinOracle)
                .getTwapCOUSDUSD();
            _price = __price * (10**(18 - __d));
        } else {
            (uint256 __price, uint8 __d) = ICoffinOracle(coffinOracle)
                .getCOUSDUSD();
            _price = __price * (10**(18 - __d));
        }
    }
    function setTaxPolicy(address _policy) external onlyOwner {
        require(_policy!=address(0), 'wrong tax policy' );
        policy = _policy;
    }
    function calcAutoTaxRate(uint256 _cousdPrice) public view returns (uint16) {
        if (policy==address(0)) {
            return 0;
        }

        return ITaxableTokenPolicy(policy).calcTaxRate(
            _cousdPrice, 
            taxThreshold, 
            adjustTaxRateA, 
            adjustTaxRateB, 
            basisTaxRate,
            maxTaxRate
        );
    }

    function getTaxInfo()
        private
        view
        returns (
            uint16 _currentTaxRate,
            uint16 _staticTaxRate,
            uint256 _burnThreshold,
            uint256 _taxThreshold,
            bool _taxActivated,
            bool _autoCalculateTax,
            uint16 _maxTaxRate,
            uint32 _adjustTaxRateA,
            bool _burnTax,
            uint256 _currentCoUSDPrice,
            uint256 __rawPrice,
            uint8 __rawDecimal,
            uint32 _adjustTaxRateB
        )
    {
        _burnThreshold = burnThreshold;
        _taxThreshold = taxThreshold;
        _taxActivated = taxActivated;
        _autoCalculateTax = autoCalculateTax;
        _maxTaxRate = maxTaxRate;
        _adjustTaxRateA = adjustTaxRateA;
        _staticTaxRate = staticTaxRate;
        (_currentTaxRate, _burnTax, _currentCoUSDPrice) = _getTaxInfo();
        (__rawPrice, __rawDecimal) = ICoffinOracle(coffinOracle).getCOUSDUSD();
        _adjustTaxRateB = adjustTaxRateB;
    }

    function _getTaxInfo()
        private
        view
        returns (
            uint16 currentTaxRate,
            bool burnTax,
            uint256 currentCoUSDPrice
        )
    {
        if (taxActivated) {
            (currentCoUSDPrice) = _getCoUSDPrice();
            if (currentCoUSDPrice > 0 && currentCoUSDPrice < taxThreshold) {
                if (currentCoUSDPrice < burnThreshold) {
                    burnTax = true;
                }
                if (autoCalculateTax) {
                    currentTaxRate = calcAutoTaxRate(currentCoUSDPrice);
                } else {
                    currentTaxRate = staticTaxRate;
                }
            }
        }
    }
    
    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal override {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");
        require(amount > 0, "Transfer amount must be greater than zero");
        
        
        (uint16 currentTaxRate, bool burnTax, ) = _getTaxInfo();

        latestTaxRate = currentTaxRate;
        if (
            currentTaxRate == 0 ||
            coffin_pools[sender] ||
            coffin_pools[recipient] ||
            _isExcluded[sender] ||
            _isExcluded[recipient]
        ) {
            super._transfer(sender, recipient, amount);
        } else {
            _transferWithTax(
                sender,
                recipient,
                amount,
                currentTaxRate,
                burnTax
            );
        }
        
    }


    function _transferWithTax(
        address sender,
        address recipient,
        uint256 amount,
        uint16 _taxRate,
        bool burnTax
    ) internal returns (bool) {

        if (_taxRate>maxTaxRate) {
            _taxRate = maxTaxRate;
        }

        uint256 taxAmount = amount.mul(_taxRate).div(10000);
        uint256 amountAfterTax = amount.sub(taxAmount);

        require(taxAmount < amount, "the tax amount should be less than the transferred amount.");

        if (burnTax) {
            // Burn tax
            if (taxAmount>0) {
                super._burn(sender, taxAmount);
            }
        } else {
            // Transfer tax to tax collector
            if (taxAmount>0) {
                super._transfer(sender, taxCollectorAddress, taxAmount);
            }   
        }

        // Transfer amount after tax to recipient
        if (amountAfterTax>0) {
            super._transfer(sender, recipient, amountAfterTax);
        }
        
        return true;
    }

    /********** onlyOwnerOrTaxOffice ************/
    // set coffinOracle
    function setCoffinOracle(address _coffinOracle)
        public
        onlyOwnerOrTaxOffice
    {
        require(
            _coffinOracle != address(0),
            "oracle address cannot be 0 address"
        );
        coffinOracle = _coffinOracle;
    }

    function enableAutoCalculateTax() public onlyOwnerOrTaxOffice {
        autoCalculateTax = true;
    }

    function disableAutoCalculateTax() public onlyOwnerOrTaxOffice {
        autoCalculateTax = false;
    }
    
    function enableTwap() public onlyOwnerOrTaxOffice {
        using_twap = true;
    }

    function disablTwap() public onlyOwnerOrTaxOffice {
        using_twap = false;
    }

    function enableTax() public onlyOwnerOrTaxOffice {
        taxActivated = true;
    }

    function disableTax() public onlyOwnerOrTaxOffice {
        taxActivated = false;
    }

    function setTaxOffice(address _taxOffice) public onlyOwnerOrTaxOffice {
        require(
            _taxOffice != address(0),
            "tax office address cannot be 0 address"
        );
        emit TaxOfficeTransferred(taxOffice, _taxOffice);
        taxOffice = _taxOffice;
    }

    function setTaxCollectorAddress(address _taxCollectorAddress)
        public
        onlyOwnerOrTaxOffice
    {
        require(
            _taxCollectorAddress != address(0),
            "tax collector address must be non-zero address"
        );
        taxCollectorAddress = _taxCollectorAddress;
    }



    function excludeAddressFromTax(address account)
        external
        onlyOwnerOrTaxOffice
        returns (bool)
    {
        require(!_isExcluded[account], "Account is already excluded");
        _isExcluded[account] = true;
        return true;
    }

    function includeAddressInTax(address account)
        external
        onlyOwnerOrTaxOffice
        returns (bool)
    {
        require(_isExcluded[account], "Account is already included");
        _isExcluded[account] = false;
        return true;
    }

    function isExcluded(address account) public view returns (bool) {
        return _isExcluded[account];
    }

    function setTaxThreshold(uint256 _taxThreshold)
        public
        onlyOwnerOrTaxOffice
        returns (bool)
    {
        taxThreshold = _taxThreshold;
        return true;
    }

    function setBurnThreshold(uint256 _burnThreshold)
        public
        onlyOwnerOrTaxOffice
        returns (bool)
    {
        burnThreshold = _burnThreshold;
        return true;
    }

    function setStaticTaxRate(uint16 _staticTaxRate)
        public
        onlyOwnerOrTaxOffice
    {
        require(staticTaxRate < 2500, "Tax rates are too high. ");
        staticTaxRate = _staticTaxRate;
    }

    function setBasisTaxRate(uint16 _basisTaxRate) public onlyOwnerOrTaxOffice {
        require(basisTaxRate < 300, "basis tax rates should be only few. ");
        basisTaxRate = _basisTaxRate;
    }

    function setMaxTaxRate(uint16 _maxTaxRate) public onlyOwnerOrTaxOffice {
        require(_maxTaxRate < 5000, "Tax rates are too high.");
        maxTaxRate = _maxTaxRate;
    }

    function setAdjustTaxRateA(uint32 _adjustTaxRate)
        public
        onlyOwnerOrTaxOffice
    {
        // for adjustmentA
        adjustTaxRateA = _adjustTaxRate;
    }

    function setAdjustTaxRateB(uint32 _adjustTaxRate)
        public
        onlyOwnerOrTaxOffice
    {
        // for adjustmentB
        adjustTaxRateB = _adjustTaxRate;
    }

    event TaxOfficeTransferred(address oldAddress, address newAddress);
}

File 12 of 24 : ERC20Burnable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../ERC20.sol";
import "../../../utils/Context.sol";

/**
 * @dev Extension of {ERC20} that allows token holders to destroy both their own
 * tokens and those that they have an allowance for, in a way that can be
 * recognized off-chain (via event analysis).
 */
abstract contract ERC20Burnable is Context, ERC20 {
    /**
     * @dev Destroys `amount` tokens from the caller.
     *
     * See {ERC20-_burn}.
     */
    function burn(uint256 amount) public virtual {
        _burn(_msgSender(), amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, deducting from the caller's
     * allowance.
     *
     * See {ERC20-_burn} and {ERC20-allowance}.
     *
     * Requirements:
     *
     * - the caller must have allowance for ``accounts``'s tokens of at least
     * `amount`.
     */
    function burnFrom(address account, uint256 amount) public virtual {
        uint256 currentAllowance = allowance(account, _msgSender());
        require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance");
        unchecked {
            _approve(account, _msgSender(), currentAllowance - amount);
        }
        _burn(account, amount);
    }
}

File 13 of 24 : CoffinOracle.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";

import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IUniswapV2Router02.sol";
import "./interfaces/IUniswapV2Factory.sol";
import "./interfaces/IUniswapLP.sol";
import "./libs/FixedPoint.sol";
import "./interfaces/IBandStdReference.sol";


interface ICoffinOracle {
    function PERIOD() external view returns (uint32);
    function getCOFFINUSD() external view returns (uint256, uint8);
    function updateTwap(address token0, address token1) external ;
    function getCOUSDUSD() external view returns (uint256, uint8);
    function getTwapCOUSDUSD() external view returns (uint256, uint8);
    function getTwapCOFFINUSD() external view returns (uint256, uint8);
    function getTwapXCOFFINUSD() external view returns (uint256, uint8);
    function updateTwapDollar() external ;
    function updateTwapCoffin() external ;
    function updateTwapXCoffin() external ;
    function getXCOFFINUSD() external view returns (uint256, uint8);
    function getCOUSDFTM() external view returns (uint256, uint8);
    function getXCOFFINFTM() external view returns (uint256, uint8);
    function getCOFFINFTM() external view returns (uint256, uint8);
    function getFTMUSD() external view returns (uint256, uint8);

}

contract MockCoffinOracle is ICoffinOracle, Ownable {
    uint256 public xcoffinftm = (1 / 2) * 1 * 10**18;
    uint256 public coffinftm = 2 * 1 * 10**18;
    uint256 public ftmusd = (1 / 4) * 1 * 10**18;
    uint256 public cousdftm = (101 / 100) * 4 * 1 * 10**18;
    uint32 public override PERIOD = 600; // 10-minute TWAP 

    function updateTwap(address token0, address token1) external override {

    }
    function updateTwapDollar() external override{

    }
    function updateTwapCoffin() external override{

    }
    function updateTwapXCoffin() external override{

    }
    function setCOUSDFTM(uint256 val) external {
        cousdftm = val;
    }

    function getCOUSDFTM() public view override returns (uint256, uint8) {
        return (cousdftm, 18);
    }

    function setXCOFFINFTM(uint256 val) external {
        xcoffinftm = val;
    }

    function getXCOFFINFTM() public view override returns (uint256, uint8) {
        return (xcoffinftm, 18);
    }

    function setCOFFINFTM(uint256 val) external {
        coffinftm = val;
    }

    function getCOFFINFTM() public view override returns (uint256, uint8) {
        return (coffinftm, 18);
    }

 
    uint256 public cousdusd = 1030000000000000000;
    function setCOUSDUSD(uint256 val) external {
        cousdusd = val;// decimal 18 
    }
    function getCOUSDUSD() public view override returns(uint256,uint8){
        return (cousdusd,18);// decimal 18 
    }
    
 
    
    function setFTMUSD(uint256 val) external {
        ftmusd = val;
    }

    function getFTMUSD() public view override returns (uint256, uint8) {
        return (ftmusd, 18);
    }


    function getCOFFINUSD() public view override returns (uint256, uint8) {
        (uint256 v1, uint8 d1) = getCOFFINFTM();
        (uint256 v2, uint8 d2) = getFTMUSD();
        return ((v1 * v2) / (10**d1), d2);
    }

    function getXCOFFINUSD() public view override returns (uint256, uint8) {
        (uint256 v1, uint8 d1) = getXCOFFINFTM();
        (uint256 v2, uint8 d2) = getFTMUSD();
        return ((v1 * v2) / (10**d1), d2);
    }

    function getTwapCOUSDUSD() external view override returns (uint256, uint8){
        return getCOUSDUSD();
    }
    function getTwapCOFFINUSD() external view override returns (uint256, uint8){
        return getCOFFINUSD();
    }
    function getTwapXCOFFINUSD() external view override returns (uint256, uint8){
        return getXCOFFINUSD();
    }

}


contract CoffinOracle is ICoffinOracle, Initializable,Ownable {
    using SafeMath for uint256;
    using FixedPoint for *;

    IUniswapV2Router02 public uniswapv2router;
    address public coffin;
    address public dollar;
    address public xcoffin;
    address public wftm = 0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83;
    address public usdc = 0x04068DA6C83AFCFA0e13ba15A6696662335D5B75;
    address public boo = 0x841FAD6EAe12c286d1Fd18d1d525DFfA75C7EFFE;
    address public dai = 0x8D11eC38a3EB5E956B052f67Da8Bdc9bef8Abf3E;
    IBandStdReference bandRef;
    uint32 public override PERIOD = 600; // 10-minute TWAP

    struct Pair {
        uint256 price0CumulativeLast;
        uint256 price1CumulativeLast;
        uint32 blockTimestampLast;
        FixedPoint.uq112x112 price0Average;
        FixedPoint.uq112x112 price1Average;
        bool initialized;
    }

    mapping(address => Pair) public getPair;

    function setPeriod(uint32 _period) external onlyOwner {
        PERIOD = _period;
    }

    function init(
        address _coffinAddress,
        address _cousdAddress,
        address _xcoffinAddress
    ) external  initializer onlyOwner{
        // router address. it's spooky router by default. 
        address routerAddress = 0xF491e7B69E4244ad4002BC14e878a34207E38c29;
        setRouter(routerAddress);

        address fantomBandProtocol = 0x56E2898E0ceFF0D1222827759B56B28Ad812f92F;

        setBandOracle(fantomBandProtocol);
        setCOFFINAddress(_coffinAddress);
        setDollarAddress(_cousdAddress);
        setXCOFFINAddress(_xcoffinAddress);
    }

    function getBandRate(string memory token0, string memory token1)
        public
        view
        returns (uint256)
    {
        IBandStdReference.ReferenceData memory data = bandRef.getReferenceData(
            token0,
            token1
        );
        return data.rate;
    }


    function getFTMUSD() public view override returns (uint256, uint8) {
        return (getBandRate("FTM","USD"), 18);
    }

    



    function setCOFFINAddress(address _coffinAddress) public onlyOwner {
        coffin = _coffinAddress;
    }

    function setXCOFFINAddress(address _xcoffinAddress) public onlyOwner {
        xcoffin = _xcoffinAddress;
    }

    function setDollarAddress(address _cousdAddress) public onlyOwner {
        dollar = _cousdAddress;
    }

    function setRouter(address _uniswapv2routeraddress)
        public
        onlyOwner
    {
        uniswapv2router = IUniswapV2Router02(_uniswapv2routeraddress);
    }

    function setBandOracle(address _bandOracleAddress) public onlyOwner {
        bandRef = IBandStdReference(_bandOracleAddress);
    }


    function getCOFFINUSD() external view override returns (uint256, uint8) {
        (uint256 v1, uint8 d1) = getCOFFINFTM();
        (uint256 v2, uint8 d2) = getFTMUSD();
        return ((v1 * v2) / (10**d1), d2);
    }

    function getTwapCOFFINUSD() external view override returns (uint256, uint8) {
        (uint256 v1, uint8 d1) = getTwapCOFFINFTM();
        (uint256 v2, uint8 d2) = getFTMUSD();
        return ((v1 * v2) / (10**d1), d2);
    }
    
    function getUSDCUSD() public view  returns (uint256, uint8) {
        return (getBandRate("USDC","USD"), 18);
    }
    function getDAIUSD() public view  returns (uint256, uint8) {
        return (getBandRate("DAI","USD"), 18);
    }
    
    uint8 public oracleMode = 0; 

    function enableFTMOracle() external onlyOwner {
        oracleMode = 1;
    }
    function enableDAIOracle() external onlyOwner {
        oracleMode = 2 ;
    }
    function enableUSDCracle() external onlyOwner {
        oracleMode = 0 ;
    }

    function getCOUSDUSD() external view override returns (uint256, uint8) {
        if (oracleMode==1) {
            (uint256 v1, uint8 d1) = getCOUSDFTM();
            (uint256 v2, uint8 d2) = getFTMUSD();
            return ((v1 * v2) / (10**d1), d2);
        } else if (oracleMode==2) {
            (uint256 v1, uint8 d1) = getCOUSDDAI();
            (uint256 v2, uint8 d2) = getDAIUSD();
            return ((v1 * v2) / (10**d1), d2);
        } else {
            (uint256 v1, uint8 d1) = getCOUSDUSDC();
            (uint256 v2, uint8 d2) = getUSDCUSD();
            return ((v1 * v2) / (10**d1), d2);
        }
    }

    function getTwapCOUSDUSD() external view override returns (uint256, uint8) {
        if (oracleMode==1) {
            (uint256 v1, uint8 d1) = getTwapCOUSDFTM();
            (uint256 v2, uint8 d2) = getFTMUSD();
            return ((v1 * v2) / (10**d1), d2);
        } else if (oracleMode==2) {   
            (uint256 v1, uint8 d1) = getTwapCOUSDDAI();
            (uint256 v2, uint8 d2) = getDAIUSD();
            return ((v1 * v2) / (10**d1), d2);
        } else {
            (uint256 v1, uint8 d1) = getTwapCOUSDUSDC();
            (uint256 v2, uint8 d2) = getUSDCUSD();
            return ((v1 * v2) / (10**d1), d2);     
        }

    }

    
    


    function getXCOFFINUSD() external view override returns (uint256, uint8) {
        (uint256 v1, uint8 d1) = getXCOFFINFTM();
        (uint256 v2, uint8 d2) = getFTMUSD();
        return ((v1 * v2) / (10**d1), d2);
    }

    function getTwapXCOFFINUSD() external view override returns (uint256, uint8) {
        (uint256 v1, uint8 d1) = getTwapXCOFFINFTM();
        (uint256 v2, uint8 d2) = getFTMUSD();
        return ((v1 * v2) / (10**d1), d2);
    }

    function getTwapCOUSDFTM() public view  returns (uint256, uint8) {
        (uint256 a, uint8 b) = getTwapRate(dollar,wftm);
        if (a>0) {
            return (a,b);
        }
        return getRealtimeRate(dollar,wftm);
    }
    
    function getTwapCOUSDDAI() public view  returns (uint256, uint8) {
        (uint256 a, uint8 b) = getTwapRate(dollar,dai);
        if (a>0) {
            return (a,b);
        }
        return getRealtimeRate(dollar,usdc);
    }
    function getTwapCOUSDUSDC() public view  returns (uint256, uint8) {
        (uint256 a, uint8 b) = getTwapRate(dollar,usdc);
        if (a>0) {
            return (a,b);
        }
        return getRealtimeRate(dollar,usdc);
    }
    
    function getCOUSDFTM() public view override returns (uint256, uint8) {
        return getRealtimeRate(dollar,wftm);
    }
    function getCOUSDUSDC() public view returns (uint256, uint8) {
        return getRealtimeRate(dollar,usdc);
    }
    function getCOUSDDAI() public view returns (uint256, uint8) {
        return getRealtimeRate(dollar,dai);
    }
    

    function getTwapXCOFFINFTM() public view  returns (uint256, uint8) {
        (uint256 a, uint8 b) = getTwapRate(xcoffin,wftm);
        if (a>0) {
            return (a,b);
        }
        return getRealtimeRate(xcoffin,wftm);
    }

    function getXCOFFINFTM() public view override returns (uint256, uint8) {
        return getRealtimeRate(xcoffin,wftm);
    }

    function getTwapCOFFINFTM() public view returns (uint256, uint8) {
        (uint256 a, uint8 b) = getTwapRate(coffin,wftm);
        if (a>0) {
            return (a,b);
        }
        return getRealtimeRate(coffin,wftm);
    }
    function getCOFFINFTM() public view override returns (uint256, uint8) {
        return getRealtimeRate(coffin,wftm);
    }


    function currentBlockTimestamp() internal view returns (uint32) {
        return uint32(block.timestamp % 2**32);
    }

    function currentCumulativePrices(address uniswapV2Pair)
        internal
        view
        returns (
            uint256 price0Cumulative,
            uint256 price1Cumulative,
            uint32 blockTimestamp
        )
    {
        // Pair storage pairStorage = getPair[uniswapV2Pair];

        blockTimestamp = currentBlockTimestamp();
        IUniswapLP uniswapPair = IUniswapLP(uniswapV2Pair);
        price0Cumulative = uniswapPair.price0CumulativeLast();
        price1Cumulative = uniswapPair.price1CumulativeLast();

        // if time has elapsed since the last update on the pair, mock the accumulated price values
        (uint112 reserve0, uint112 reserve1, uint32 _blockTimestampLast) = uniswapPair.getReserves();
        if (_blockTimestampLast != blockTimestamp) {
            // subtraction overflow is desired
            uint32 timeElapsed = blockTimestamp - _blockTimestampLast;
            // addition overflow is desired
            // counterfactual
            price0Cumulative += uint256(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed;
            // counterfactual
            price1Cumulative += uint256(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed;
        }
    }


    function getTwapRate(address token0, address token1)
        public
        view
        returns (uint256 priceLatest, uint8 decimals)
    {
        address[] memory path = new address[](2);
        path[0] = token0;
        path[1] = token1;
        address factory = address(uniswapv2router.factory());
        address uniswapV2Pair = IUniswapV2Factory(factory).getPair(token0, token1);

        if (uniswapV2Pair== address(0)) {
            return (0,0);
        } 

        // Pair memory pair = getPair[uniswapV2Pair];
        Pair storage pairStorage = getPair[uniswapV2Pair];

        // require(pairStorage.initialized, "need to setup first");
        if (!pairStorage.initialized) {
            return getRealtimeRate(token0, token1);
            // return (0,0);
        }
        
        (uint256 price0Cumulative, uint256 price1Cumulative, uint32 blockTimestamp) = currentCumulativePrices(
            address(uniswapV2Pair)
        );
        uint32 timeElapsed = blockTimestamp - pairStorage.blockTimestampLast; // Overflow is desired

        FixedPoint.uq112x112 memory price0Average 
            = FixedPoint.uq112x112(uint224((price0Cumulative - pairStorage.price0CumulativeLast) / timeElapsed));
        FixedPoint.uq112x112 memory price1Average 
            = FixedPoint.uq112x112(uint224((price1Cumulative - pairStorage.price1CumulativeLast) / timeElapsed));

        uint256 amountIn = 1e18;
        if (IUniswapLP(uniswapV2Pair).token0() == token0) {
            priceLatest = uint256(price0Average.mul(amountIn).decode144());
            decimals = ERC20(token1).decimals();
        } else {
            require(IUniswapLP(uniswapV2Pair).token0() == token1, "TwapOracle: INVALID_TOKEN");
            priceLatest = uint256(price1Average.mul(amountIn).decode144());
            decimals = ERC20(token0).decimals();
        }
    }

    function getTwapRateWithUpdate(address token0, address token1)
        external
        returns (uint256 priceLatest, uint8 decimals)
    {
        updateTwap(token0,token1);
        return getTwapRate(token0,token1);
    }
    

    function updateTwapDollarFTM() public  {
        updateTwap(dollar, wftm);
    }
    function updateTwapDollar() public override {
        updateTwap(dollar, dai);
    }
    function updateTwapDollarUSDC() public  {
        updateTwap(dollar, usdc);
    }
    function updateTwapCoffin() public override {
        updateTwap(coffin, wftm);
    }
    function updateTwapXCoffin() public override {
        updateTwap(xcoffin, wftm);
    }

    function updateTwap(address token0, address token1) public override {

        address[] memory path = new address[](2);
        path[0] = token0;
        path[1] = token1;
        address factory = address(uniswapv2router.factory());
        address uniswapV2Pair = IUniswapV2Factory(factory).getPair(token0, token1);

        if (uniswapV2Pair== address(0)) {
            return;
        }
        Pair storage pairStorage = getPair[uniswapV2Pair];
        // require(pairStorage.initialized, "need to setup first");
        
        (uint256 price0Cumulative, uint256 price1Cumulative, uint32 blockTimestamp) = currentCumulativePrices(
            address(uniswapV2Pair)
        );

        if (!pairStorage.initialized) {
            // first time 
            pairStorage.price0CumulativeLast = price0Cumulative;
            pairStorage.price1CumulativeLast = price1Cumulative;
            pairStorage.blockTimestampLast = blockTimestamp;
            pairStorage.initialized = true;
            return;
        }

        // Overflow is desired
        uint32 timeElapsed = blockTimestamp - pairStorage.blockTimestampLast; 
        
        // Ensure that at least one full period has passed since the last update
        if (timeElapsed < PERIOD) {
            return ;
        }
        
        pairStorage.price0Average 
            = FixedPoint.uq112x112(uint224((price0Cumulative - pairStorage.price0CumulativeLast) / timeElapsed));
        pairStorage.price1Average 
            = FixedPoint.uq112x112(uint224((price1Cumulative - pairStorage.price1CumulativeLast) / timeElapsed));
        pairStorage.price0CumulativeLast = price0Cumulative;
        pairStorage.price1CumulativeLast = price1Cumulative;
        pairStorage.blockTimestampLast = blockTimestamp;
    }

    function getRealtimeRate(address tokenA, address tokenB)
        public
        view
        returns (uint256 priceLatest, uint8 decimals)
    {

        address factory = address(uniswapv2router.factory());
        address pair = IUniswapV2Factory(factory).getPair(tokenA, tokenB);
        if (pair== address(0)) {
            return (0,0);
        }
        
        (uint112 reserve0, uint112 reserve1,) =
            IUniswapLP(pair).getReserves();
        if (IUniswapLP(pair).token0()==address(tokenA)) {
            priceLatest = uint256(reserve1).mul(uint256(10**ERC20(tokenA).decimals())).div(uint256(reserve0));
            decimals = ERC20(tokenB).decimals();
        } else {
            priceLatest = uint256(reserve0).mul(uint256(10**ERC20(tokenA).decimals())).div(uint256(reserve1));
            decimals = ERC20(tokenB).decimals();
        }

        if ((18-decimals)>0) { 
            priceLatest = priceLatest.mul(10**(18-decimals));
            decimals = 18;
        }
    }
}

File 14 of 24 : PoolToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";

contract PoolToken is ERC20Burnable , Ownable{
    using SafeMath for uint256;

    // The addresses in this array are added by the oracle and these contracts are able to mint coffin
    address[] public coffin_pools_array;

    // Mapping is also used for faster verification
    mapping(address => bool) public coffin_pools; 

    /* ========== MODIFIERS ========== */

    modifier onlyPools() {
        require(coffin_pools[msg.sender] == true, "Only coffin pools can call this function");
        _;
    }
    

    modifier onlyByOwnerOrPool() {
        require(
            msg.sender == owner()
            || coffin_pools[msg.sender] == true, 
            "You are not the owner, or a pool");
        _;
    }

    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /* ========== constructor ========== */
    constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {}
    /* ========== view ========== */
    function poolLength() view public returns(uint256) {
        return coffin_pools_array.length;
    }

    /* ========== onlyPools ========== */

    // Used by pools when user redeems
    function pool_burn_from(address addr, uint256 amount) public onlyPools {
        super.burnFrom(addr, amount);
        emit Burned(addr, msg.sender, amount);
    }
    // This function is what other pools will call to mint new token 
    function pool_mint(address addr, uint256 amount) public onlyPools {
        super._mint(addr, amount);
        emit Minted(msg.sender, addr, amount);
    }

    /* ========== onlyOwner  ========== */

    // 
    function burnFrom(address addr, uint256 amount) public override onlyOwner {
        super.burnFrom(addr, amount);
        emit Minted(msg.sender, addr, amount);
    }
    
    // pools which can mint/burn 
    function addPool(address pool_address) public onlyOwner {
        require(pool_address != address(0), "Zero address detected");

        require(coffin_pools[pool_address] == false, "Address already exists");
        coffin_pools[pool_address] = true; 
        coffin_pools_array.push(pool_address);

        emit PoolAdded(pool_address);
    }

    // Remove a pool 
    function removePool(address pool_address) public onlyOwner {
        require(pool_address != address(0), "Zero address detected");
        require(coffin_pools[pool_address] == true, "Address nonexistant");
        
        // Delete from the mapping
        delete coffin_pools[pool_address];

        // 'Delete' from the array by setting the address to 0x0
        for (uint i = 0; i < coffin_pools_array.length; i++){ 
            if (coffin_pools_array[i] == pool_address) {
                coffin_pools_array[i] = address(0); // This will leave a null in the array and keep the indices the same
                break;
            }
        }

        emit PoolRemoved(pool_address);
    }

    /* ========== EVENTS ========== */


    event Burned(address indexed from, address indexed by, uint256 amount);
    event Minted(address indexed from, address indexed to, uint256 amount);
    event PoolAdded(address pool_address);
    event PoolRemoved(address pool_address);

}

File 15 of 24 : Babylonian.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

// computes square roots using the babylonian method
// https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
library Babylonian {
    function sqrt(uint256 y) internal pure returns (uint256 z) {
        if (y > 3) {
            z = y;
            uint256 x = y / 2 + 1;
            while (x < z) {
                z = x;
                x = (y / x + x) / 2;
            }
        } else if (y != 0) {
            z = 1;
        }
        // else z = 0
    }
}

File 16 of 24 : ITaxableTokenPolicy.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

    
interface ITaxableTokenPolicy  {
    function calcTaxRate(
        uint256 dollarPrice, 
        uint256 taxThreshold, 
        uint256 paramA, 
        uint256 paramB, 
        uint256 basisTaxRate,
        uint256 maxTaxRate
    ) external pure returns (uint16) ;
    }

File 17 of 24 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin guidelines: functions revert instead
 * of returning `false` on failure. This behavior is nonetheless conventional
 * and does not conflict with the expectations of ERC20 applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5,05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
            _approve(sender, _msgSender(), currentAllowance - amount);
        }

        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        uint256 currentAllowance = _allowances[_msgSender()][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(_msgSender(), spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `sender` to `recipient`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[sender] = senderBalance - amount;
        }
        _balances[recipient] += amount;

        emit Transfer(sender, recipient, amount);

        _afterTokenTransfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

File 18 of 24 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 19 of 24 : IUniswapV2Router02.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.11;

import "./IUniswapV2Router01.sol";

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountETH);

    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;

    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable;

    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;

}

File 20 of 24 : IUniswapV2Factory.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.7;
interface IUniswapV2Factory {

    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);

    function getPair(address tokenA, address tokenB) external view returns (address pair);
    function allPairs(uint) external view returns (address pair);
    function allPairsLength() external view returns (uint);

    function createPair(address tokenA, address tokenB) external returns (address pair);

    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
}

File 21 of 24 : IUniswapLP.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.7;
pragma experimental ABIEncoderV2;

interface IUniswapLP {
    function token0() external view returns (address);

    function token1() external view returns (address);

    function getReserves()
        external
        view
        returns (
            uint112 reserve0,
            uint112 reserve1,
            uint32 blockTimestampLast
        );

    function price0CumulativeLast() external view returns (uint256);

    function price1CumulativeLast() external view returns (uint256);

    function getTokenWeights() external view returns (uint32 tokenWeight0, uint32 tokenWeight1);
}

File 22 of 24 : FixedPoint.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

import "./Babylonian.sol";

// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
library FixedPoint {
    // range: [0, 2**112 - 1]
    // resolution: 1 / 2**112
    struct uq112x112 {
        uint224 _x;
    }

    // range: [0, 2**144 - 1]
    // resolution: 1 / 2**112
    struct uq144x112 {
        uint256 _x;
    }

    uint8 private constant RESOLUTION = 112;
    uint256 private constant Q112 = uint256(1) << RESOLUTION;
    uint256 private constant Q224 = Q112 << RESOLUTION;

    // encode a uint112 as a UQ112x112
    function encode(uint112 x) internal pure returns (uq112x112 memory) {
        return uq112x112(uint224(x) << RESOLUTION);
    }

    // encodes a uint144 as a UQ144x112
    function encode144(uint144 x) internal pure returns (uq144x112 memory) {
        return uq144x112(uint256(x) << RESOLUTION);
    }

    // divide a UQ112x112 by a uint112, returning a UQ112x112
    function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) {
        require(x != 0, "FixedPoint: DIV_BY_ZERO");
        return uq112x112(self._x / uint224(x));
    }

    // multiply a UQ112x112 by a uint, returning a UQ144x112
    // reverts on overflow
    function mul(uq112x112 memory self, uint256 y) internal pure returns (uq144x112 memory) {
        uint256 z;
        require(y == 0 || (z = uint256(self._x) * y) / y == uint256(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW");
        return uq144x112(z);
    }

    // returns a UQ112x112 which represents the ratio of the numerator to the denominator
    // equivalent to encode(numerator).div(denominator)
    function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) {
        require(denominator > 0, "FixedPoint: DIV_BY_ZERO");
        return uq112x112((uint224(numerator) << RESOLUTION) / denominator);
    }

    // decode a UQ112x112 into a uint112 by truncating after the radix point
    function decode(uq112x112 memory self) internal pure returns (uint112) {
        return uint112(self._x >> RESOLUTION);
    }

    // decode a UQ144x112 into a uint144 by truncating after the radix point
    function decode144(uq144x112 memory self) internal pure returns (uint144) {
        return uint144(self._x >> RESOLUTION);
    }

    // take the reciprocal of a UQ112x112
    function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) {
        require(self._x != 0, "FixedPoint: ZERO_RECIPROCAL");
        return uq112x112(uint224(Q224 / self._x));
    }

    // square root of a UQ112x112
    function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) {
        return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56));
    }
}

File 23 of 24 : IBandStdReference.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

interface IBandStdReference {
    /// A structure returned whenever someone requests for standard reference data.
    struct ReferenceData {
        uint256 rate; // base/quote exchange rate, multiplied by 1e18.
        uint256 lastUpdatedBase; // UNIX epoch of the last time when base price gets updated.
        uint256 lastUpdatedQuote; // UNIX epoch of the last time when quote price gets updated.
    }

    /// Returns the price data for the given base/quote pair. Revert if not available.
    function getReferenceData(string memory _base, string memory _quote)
        external
        view
        returns (ReferenceData memory);
    
    /// Similar to getReferenceData, but with multiple base/quote pairs at once.
    function getReferenceDataBulk(
        string[] memory _bases,
        string[] memory _quotes
    ) external view returns (ReferenceData[] memory);
}

File 24 of 24 : IUniswapV2Router01.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

interface IUniswapV2Router01 {
    function factory() external view   returns (address);
    function WETH() external view  returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 500
  },
  "metadata": {
    "bytecodeHash": "none",
    "useLiteralContent": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"pid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EmergencyWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"pid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"to","type":"address"}],"name":"EventDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"pid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"_to","type":"address"}],"name":"EventHarvest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EventSafeRewardTransfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"dev_fund","type":"address"}],"name":"EventSetDev","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_marketing_fund","type":"address"}],"name":"EventSetMarketingFund","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"pid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"to","type":"address"}],"name":"EventWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"DEFAULT_VESTING_DRATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAXIMUM_HARVEST_INTERVAL","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAXIMUM_LOCKUP_INTERVAL","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STARTING_WITHIN","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOTAL_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_allocPoint","type":"uint256"},{"internalType":"address","name":"_lpToken","type":"address"},{"internalType":"uint256","name":"_harvestInterval","type":"uint256"},{"internalType":"uint256","name":"_withdrawLockupTime","type":"uint256"},{"internalType":"bool","name":"withUpdateAllPool","type":"bool"}],"name":"addPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"},{"internalType":"address","name":"_user","type":"address"}],"name":"canHarvest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"},{"internalType":"address","name":"_user","type":"address"}],"name":"canWithdraw","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_to","type":"address"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"dev_fund","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"}],"name":"emergencyWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"endTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"},{"internalType":"address","name":"_to","type":"address"}],"name":"harvest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_rewardToken","type":"address"},{"internalType":"uint256","name":"_startTime","type":"uint256"},{"internalType":"uint256","name":"_rewardPerSecond","type":"uint256"}],"name":"init","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"marketing_fund","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"massUpdatePools","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"},{"internalType":"address","name":"_user","type":"address"}],"name":"pendingReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"poolExistence","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"poolInfo","outputs":[{"internalType":"contract IERC20","name":"lpToken","type":"address"},{"internalType":"uint256","name":"allocPoint","type":"uint256"},{"internalType":"uint256","name":"lastRewardTime","type":"uint256"},{"internalType":"uint256","name":"accRewardPerShare","type":"uint256"},{"internalType":"uint256","name":"harvestInterval","type":"uint256"},{"internalType":"uint256","name":"withdrawLockupTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"}],"name":"poolTokenBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardPerSecond","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardToken","outputs":[{"internalType":"contract Coffin","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_dev_fund","type":"address"}],"name":"setDevFund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_marketing_fund","type":"address"}],"name":"setMarketingFund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"},{"internalType":"uint256","name":"_allocPoint","type":"uint256"},{"internalType":"uint256","name":"_harvestInterval","type":"uint256"},{"internalType":"uint256","name":"_withdrawLockupTime","type":"uint256"}],"name":"setPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_rewardPerSecond","type":"uint256"}],"name":"setRewardPerSecond","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_startTime","type":"uint256"}],"name":"setStartTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAllocPoint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalMintedReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"}],"name":"updatePool","outputs":[{"components":[{"internalType":"contract IERC20","name":"lpToken","type":"address"},{"internalType":"uint256","name":"allocPoint","type":"uint256"},{"internalType":"uint256","name":"lastRewardTime","type":"uint256"},{"internalType":"uint256","name":"accRewardPerShare","type":"uint256"},{"internalType":"uint256","name":"harvestInterval","type":"uint256"},{"internalType":"uint256","name":"withdrawLockupTime","type":"uint256"}],"internalType":"struct CoffinMaker.PoolInfo","name":"pool","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"pids","type":"uint256[]"}],"name":"updatePools","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"userInfo","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"int256","name":"rewardDebt","type":"int256"},{"internalType":"uint256","name":"nextHarvestUntil","type":"uint256"},{"internalType":"uint256","name":"depositTimerStart","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_to","type":"address"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"pid","type":"uint256"}],"name":"withdrawLockup","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

608060405260006008556305a39a80600d556a52b7d2dcc80cd2e4000000600e5534801561002c57600080fd5b506100363361003f565b6001805561008f565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6131c5806200009f6000396000f3fe608060405234801561001057600080fd5b506004361061023d5760003560e01c8063867828131161013b578063b562f7af116100b8578063f2fde38b1161007c578063f2fde38b1461056f578063f462101e14610582578063f7c618c114610595578063fbbb0df3146105a8578063feeb26a8146105b257600080fd5b8063b562f7af1461051d578063c776cb8914610526578063cbd258b514610539578063da65a8dd1461055c578063de73149d1461056557600080fd5b806393f1a40b116100ff57806393f1a40b1461047157806398969e82146104d1578063a4a2a9f6146104e4578063ae4db919146104f7578063b4c965141461050a57600080fd5b806386782813146104315780638da5cb5b1461043b5780638dbdbe6d1461044c5780638f10369a1461045f578063902d55a51461046857600080fd5b80633e0a322d116101c95780635312ea8e1161018d5780635312ea8e146103f2578063630b5ba11461040557806366da58151461040d578063715018a61461042057806378e979251461042857600080fd5b80633e0a322d1461033e5780633ea01b5d1461035157806343aec3a714610364578063447809941461037757806351eb05a61461038a57600080fd5b806318fccc761161021057806318fccc76146102c157806324597f13146102d45780632e6c998d146102e75780633197cbb61461030a5780633905d8711461031357600080fd5b8063081e3eda146102425780630ad58d2f146102595780631526fe271461026e57806317caf6f1146102b8575b600080fd5b6005545b6040519081526020015b60405180910390f35b61026c610267366004612f5c565b6105c5565b005b61028161027c366004612eaa565b610a18565b604080516001600160a01b0390971687526020870195909552938501929092526060840152608083015260a082015260c001610250565b61024660085481565b61026c6102cf366004612edc565b610a68565b61026c6102e2366004612dca565b610cba565b6102fa6102f5366004612edc565b610d71565b6040519015158152602001610250565b610246600a5481565b600454610326906001600160a01b031681565b6040516001600160a01b039091168152602001610250565b61026c61034c366004612eaa565b610dec565b6102fa61035f366004612edc565b610e8a565b61026c610372366004612f08565b610f3d565b61026c610385366004612e18565b6113c0565b61039d610398366004612eaa565b611404565b6040516102509190600060c0820190506001600160a01b0383511682526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015292915050565b61026c610400366004612eaa565b6118c7565b61026c611a17565b61026c61041b366004612eaa565b611a21565b61026c611aba565b61024660095481565b61024662278d0081565b6000546001600160a01b0316610326565b61026c61045a366004612f5c565b611b0c565b610246600b5481565b610246600e5481565b6104b161047f366004612edc565b600760209081526000928352604080842090915290825290208054600182015460028301546003909301549192909184565b604080519485526020850193909352918301526060820152608001610250565b6102466104df366004612edc565b61200c565b61026c6104f2366004612de5565b6121d2565b61026c610505366004612dca565b61246e565b610246610518366004612eaa565b612527565b610246600c5481565b600354610326906001600160a01b031681565b6102fa610547366004612dca565b60066020526000908152604090205460ff1681565b610246600d5481565b6102466201518081565b61026c61057d366004612dca565b6125cf565b61026c610590366004612f91565b612688565b600254610326906001600160a01b031681565b6102466212750081565b6102466105c0366004612eaa565b6128a0565b6002600154141561061d5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064015b60405180910390fd5b60026001556009546106665760405162461bcd60e51b81526020600482015260126024820152711b9bdd081a5b9a5d1a5b1a5e9959081e595d60721b6044820152606401610614565b6001600160a01b0381166106bc5760405162461bcd60e51b815260206004820152601f60248201527f63616e6e6f7420776974686472617720746f207a65726f2061646472657373006044820152606401610614565b60006106c784611404565b6000858152600760209081526040808320338452909152902080549192509084111561075b5760405162461bcd60e51b815260206004820152603860248201527f436f6666696e4d616b65723a207769746864726177207265717565737420677260448201527f6561746572207468616e207374616b656420616d6f756e7400000000000000006064820152608401610614565b600084116107d15760405162461bcd60e51b815260206004820152603260248201527f436f6666696e4d616b65723a20776974686472617720616d6f756e742073686f60448201527f756c64206265206d6f7265207468616e203000000000000000000000000000006064820152608401610614565b428260a0015182600301546107e69190613052565b11156108475760405162461bcd60e51b815260206004820152602a60248201527f436f6666696e4d616b65723a207374696c6c20696e207769746864726177206c6044820152696f636b75702074696d6560b01b6064820152608401610614565b81516040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b15801561088a57600080fd5b505afa15801561089e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108c29190612ec3565b90506108ea64e8d4a510006108e485606001518861290290919063ffffffff16565b9061290e565b8260010160008282546108fd91906130ab565b90915550508154859083906000906109169084906130ea565b90915550508251610931906001600160a01b0316858761291a565b82516040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b15801561097457600080fd5b505afa158015610988573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109ac9190612ec3565b9050856109b982846130ea565b146109c6576109c6613148565b604080518781526001600160a01b0387166020820152889133917fc1fc7d369795ea1f99a0f1cc7f3eb4e4e2c256c001f24f3ba48f4ce7f3666ef0910160405180910390a35050600180555050505050565b60058181548110610a2857600080fd5b60009182526020909120600690910201805460018201546002830154600384015460048501546005909501546001600160a01b0390941695509193909286565b60026001541415610abb5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610614565b60026001556001600160a01b038116610b165760405162461bcd60e51b815260206004820152601f60248201527f63616e6e6f7420776974686472617720746f207a65726f2061646472657373006044820152606401610614565b6000610b2183611404565b60008481526007602090815260408083203384529091529020600281015491925090421015610bb85760405162461bcd60e51b815260206004820152602f60248201527f436f6666696e4d616b65723a206e65656420746f207761697420666f72206e6560448201527f787420686172766573742074696d6500000000000000000000000000000000006064820152608401610614565b6000610bde64e8d4a510006108e48560600151856000015461290290919063ffffffff16565b90506000826001015482610bf291906130ab565b905060008111610c445760405162461bcd60e51b815260206004820152601f60248201527f436f6666696e4d616b65723a206e6f2070656e64696e672072657761726420006044820152606401610614565b600183018290556080840151610c5a9042613052565b6002840155610c698582612997565b604080518281526001600160a01b0387166020820152879133917fbf994279e565ba90e83c9185d2c8bdc08f3e325268ace95b049d3c315080f9a1910160405180910390a350506001805550505050565b6000546001600160a01b0316331480610cdb5750336001600160a01b038216145b610d275760405162461bcd60e51b815260206004820152601a60248201527f436f6666696e4d616b65723a206f6e6c792066726f6d206465760000000000006044820152606401610614565b600480546001600160a01b0319166001600160a01b0383169081179091556040517fb5954fe3513bea0af27ed9f9d8456cfcc21456e7a77b2709748b6316f4685d4890600090a250565b600060095460001415610dbb5760405162461bcd60e51b81526020600482015260126024820152711b9bdd081a5b9a5d1a5b1a5e9959081e595d60721b6044820152606401610614565b5060008281526007602090815260408083206001600160a01b03851684529091529020600201544210155b92915050565b6000546001600160a01b03163314610e345760405162461bcd60e51b815260206004820181905260248201526000805160206131998339815191526044820152606401610614565b4260095410610e855760405162461bcd60e51b815260206004820152600f60248201527f616c7265616479207374617274656400000000000000000000000000000000006044820152606401610614565b600955565b600060095460001415610ed45760405162461bcd60e51b81526020600482015260126024820152711b9bdd081a5b9a5d1a5b1a5e9959081e595d60721b6044820152606401610614565b60008381526007602090815260408083206001600160a01b038616845290915281206005805491929186908110610f0d57610f0d613174565b906000526020600020906006020190504281600501548360030154610f329190613052565b111595945050505050565b6000546001600160a01b03163314610f855760405162461bcd60e51b815260206004820181905260248201526000805160206131998339815191526044820152606401610614565b6001600160a01b038416600090815260066020526040902054849060ff1615610ff05760405162461bcd60e51b815260206004820152601760248201527f436f6666696e4d616b65723a206475706c6963617465640000000000000000006044820152606401610614565b6002546001600160a01b03828116911614156110745760405162461bcd60e51b815260206004820152602f60248201527f436f6666696e4d616b65723a2063616e6e6f742075736520726577617264207460448201527f6f6b656e206173206c70546f6b656e00000000000000000000000000000000006064820152608401610614565b60055460005b8181101561111757826001600160a01b03166005828154811061109f5761109f613174565b60009182526020909120600690910201546001600160a01b031614156111075760405162461bcd60e51b815260206004820152601760248201527f436f6666696e4d616b65723a206475706c6963617465640000000000000000006044820152606401610614565b6111108161312d565b905061107a565b5060095461115c5760405162461bcd60e51b81526020600482015260126024820152711b9bdd081a5b9a5d1a5b1a5e9959081e595d60721b6044820152606401610614565b821561116a5761116a612b18565b620151808511156111cb5760405162461bcd60e51b815260206004820152602560248201527f436f6666696e4d616b65723a20696e76616c6964206861727665737420696e74604482015264195c9d985b60da1b6064820152608401610614565b6212750084111561122a5760405162461bcd60e51b8152602060048201526024808201527f436f6666696e4d616b65723a20696e76616c6964206c6f636b757020696e74656044820152631c9d985b60e21b6064820152608401610614565b866008600082825461123c9190613052565b90915550506001600160a01b0386166000908152600660205260408120805460ff19166001179055600954421161127557600954611277565b425b6040805160c0810182526001600160a01b03998a168152602081019a8b5290810191825260006060820181815260808301998a5260a0830198895260058054600181018255925291517f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db0600690920291820180546001600160a01b03191691909b161790995598517f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db1890155517f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db2880155505094517f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db38501555090517f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db4830155517f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db59091015550565b8060005b818110156113fe576113ed8484838181106113e1576113e1613174565b90506020020135611404565b506113f78161312d565b90506113c4565b50505050565b6114466040518060c0016040528060006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081525090565b60095461148a5760405162461bcd60e51b81526020600482015260126024820152711b9bdd081a5b9a5d1a5b1a5e9959081e595d60721b6044820152606401610614565b6005828154811061149d5761149d613174565b60009182526020918290206040805160c081018252600690930290910180546001600160a01b03168352600181015493830184905260028101549183019190915260038101546060830152600481015460808301526005015460a082015291506115495760405162461bcd60e51b815260206004820152601f60248201527f63616e6e6f7420757064617465207468697320706f6f6c20666f72206e6f77006044820152606401610614565b600e54600c5410156118c25780604001514211156118c25780516040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b1580156115a457600080fd5b505afa1580156115b8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115dc9190612ec3565b9050801561183f5760008260400151426115f691906130ea565b90506000600854611620856020015161161a600b548661290290919063ffffffff16565b90612902565b61162a919061306a565b9050600e5481600c5461163d9190613052565b111561165657600c54600e5461165391906130ea565b90505b826116668264e8d4a51000612902565b611670919061306a565b846060018181516116819190613052565b90525060035460009081906001600160a01b031615611715576116aa600c61161a85606161290e565b600254600354604051635c6b16c160e01b81526001600160a01b039182166004820152602481018490529294501690635c6b16c190604401600060405180830381600087803b1580156116fc57600080fd5b505af1158015611710573d6000803e3d6000fd5b505050505b6004546001600160a01b0316156117a557611736600861161a85606161290e565b60025460048054604051635c6b16c160e01b81526001600160a01b039182169281019290925260248201849052929350911690635c6b16c190604401600060405180830381600087803b15801561178c57600080fd5b505af11580156117a0573d6000803e3d6000fd5b505050505b6002546001600160a01b0316635c6b16c1306117cb846117c58888612b46565b90612b46565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561181157600080fd5b505af1158015611825573d6000803e3d6000fd5b5050600c546118379250905084612b52565b600c55505050505b426040830152600580548391908590811061185c5761185c613174565b600091825260209182902083516006929092020180546001600160a01b0319166001600160a01b0390921691909117815590820151600182015560408201516002820155606082015160038201556080820151600482015560a090910151600590910155505b919050565b6002600154141561191a5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610614565b60026001556009546119635760405162461bcd60e51b81526020600482015260126024820152711b9bdd081a5b9a5d1a5b1a5e9959081e595d60721b6044820152606401610614565b60006005828154811061197857611978613174565b60009182526020808320858452600782526040808520338087529352842080548582556001820186905560028201869055600382019590955560069093020180549094509192916119d6916001600160a01b0391909116908361291a565b604051818152849033907fbb757047c2b5f3974fe26b7c10f732e7bce710b0952a71082702781e62ae05959060200160405180910390a35050600180555050565b611a1f612b18565b565b6000546001600160a01b03163314611a695760405162461bcd60e51b815260206004820181905260248201526000805160206131998339815191526044820152606401610614565b600954611aad5760405162461bcd60e51b81526020600482015260126024820152711b9bdd081a5b9a5d1a5b1a5e9959081e595d60721b6044820152606401610614565b611ab5612b18565b600b55565b6000546001600160a01b03163314611b025760405162461bcd60e51b815260206004820181905260248201526000805160206131998339815191526044820152606401610614565b611a1f6000612b5e565b60026001541415611b5f5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610614565b6002600155600954611ba85760405162461bcd60e51b81526020600482015260126024820152711b9bdd081a5b9a5d1a5b1a5e9959081e595d60721b6044820152606401610614565b60008211611bf85760405162461bcd60e51b815260206004820152601d60248201527f6465706f7369742073686f756c64206265206d6f7265207468616e20300000006044820152606401610614565b6000611c0384611404565b60008581526007602090815260408083206001600160a01b03871684529091529020600554919250908510611c655760405162461bcd60e51b81526020600482015260086024820152671b9bc8195e1a5cdd60c21b6044820152606401610614565b6000826020015111611cc35760405162461bcd60e51b815260206004820152602160248201527f63616e6e6f74206465706f736974207468697320746f6b656e20666f72206e6f6044820152607760f81b6064820152608401610614565b81516040516370a0823160e01b815233600482015285916001600160a01b0316906370a082319060240160206040518083038186803b158015611d0557600080fd5b505afa158015611d19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d3d9190612ec3565b1015611da15760405162461bcd60e51b815260206004820152602d60248201527f796f7520646f6e2774206861766520656e6f7567682062616c616e636520696e60448201526c103cb7bab9103bb0b63632ba1760991b6064820152608401610614565b6001600160a01b038316331480611db757508054155b15611dd7576080820151611dcb9042613052565b60028201554260038201555b81516040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b158015611e1a57600080fd5b505afa158015611e2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e529190612ec3565b8351909150611e6c906001600160a01b0316333088612bae565b82516040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b158015611eaf57600080fd5b505afa158015611ec3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ee79190612ec3565b90506000611ef583836130ea565b905086811115611f6d5760405162461bcd60e51b815260206004820152603560248201527f20696e636f6d652076616c75652073686f756c6420626520736d616c6c65722060448201527f7468616e20617267756d656e742076616c75652e2000000000000000000000006064820152608401610614565b80846000016000828254611f819190613052565b90915550506060850151611fa19064e8d4a51000906108e4908490612902565b846001016000828254611fb49190613012565b9091555050604080518881526001600160a01b0388166020820152899133917f048b7d6c91bf86a13f68cf031cea5b6728dcf9d85e06cc7ee4a8dee210f23d35910160405180910390a3505060018055505050505050565b6000600954600014156120565760405162461bcd60e51b81526020600482015260126024820152711b9bdd081a5b9a5d1a5b1a5e9959081e595d60721b6044820152606401610614565b60095442101561206857506000610de6565b60006005848154811061207d5761207d613174565b600091825260208083208784526007825260408085206001600160a01b03898116875293528085206006949094029091016003810154815492516370a0823160e01b815230600482015291965093949291909116906370a082319060240160206040518083038186803b1580156120f357600080fd5b505afa158015612107573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061212b9190612ec3565b905083600201544211801561213f57508015155b156121a157600084600201544261215691906130ea565b9050600061217d6008546108e4886001015461161a600b548761290290919063ffffffff16565b9050612192836108e48364e8d4a51000612902565b61219c9085613052565b935050505b600183015483546121bd9064e8d4a51000906108e49086612902565b6121c791906130ab565b979650505050505050565b6000546001600160a01b0316331461221a5760405162461bcd60e51b815260206004820181905260248201526000805160206131998339815191526044820152606401610614565b6009541561226a5760405162461bcd60e51b815260206004820152600e60248201527f6f6e6c79206f6e652074696d652e0000000000000000000000000000000000006044820152606401610614565b6001600160a01b0383166122c05760405162461bcd60e51b815260206004820152601a60248201527f72657761726420746f6b656e2061646472657373206572726f720000000000006044820152606401610614565b600280546001600160a01b0319166001600160a01b0385161790554260095581156123c85742821161235a5760405162461bcd60e51b815260206004820152603360248201527f436f6666696e4d616b65723a205468652073746172742074696d65206d75737460448201527f20626520696e20746865206675747572652e20000000000000000000000000006064820152608401610614565b62278d0061236842846130ea565b11156123c25760405162461bcd60e51b815260206004820152602360248201527f436f6666696e4d616b65723a20696e76616c6964207374617274696e67207469604482015262036b2960ed1b6064820152608401610614565b60098290555b600b819055806123df57670de0b6b3a7640000600b555b600254604080516351e238e360e01b81529051612466926001600160a01b0316916351e238e3916004808301926020929190829003018186803b15801561242557600080fd5b505afa158015612439573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061245d9190612ec3565b600c5490612b52565b600c55505050565b6000546001600160a01b031633148061249157506003546001600160a01b031633145b6124dd5760405162461bcd60e51b815260206004820152601a60248201527f436f6666696e4d616b65723a206f6e6c792066726f6d206465760000000000006044820152606401610614565b600380546001600160a01b0319166001600160a01b0383169081179091556040517f1a728d773e9cc26cb9750f8f128ed598dd65c55dda674b1d71ca53b168e6627990600090a250565b6000806005838154811061253d5761253d613174565b6000918252602090912060069091020180546040516370a0823160e01b81523360048201529192506001600160a01b0316906370a082319060240160206040518083038186803b15801561259057600080fd5b505afa1580156125a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125c89190612ec3565b9392505050565b6000546001600160a01b031633146126175760405162461bcd60e51b815260206004820181905260248201526000805160206131998339815191526044820152606401610614565b6001600160a01b03811661267c5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610614565b61268581612b5e565b50565b6000546001600160a01b031633146126d05760405162461bcd60e51b815260206004820181905260248201526000805160206131998339815191526044820152606401610614565b6009546127145760405162461bcd60e51b81526020600482015260126024820152711b9bdd081a5b9a5d1a5b1a5e9959081e595d60721b6044820152606401610614565b620151808211156127755760405162461bcd60e51b815260206004820152602560248201527f436f6666696e4d616b65723a20696e76616c6964206861727665737420696e74604482015264195c9d985b60da1b6064820152608401610614565b621275008111156127d45760405162461bcd60e51b8152602060048201526024808201527f436f6666696e4d616b65723a20696e76616c6964206c6f636b757020696e74656044820152631c9d985b60e21b6064820152608401610614565b6127dc612b18565b82600585815481106127f0576127f0613174565b90600052602060002090600602016001015460085461280f91906130ea565b6128199190613052565b600881905550826005858154811061283357612833613174565b906000526020600020906006020160010181905550816005858154811061285c5761285c613174565b906000526020600020906006020160040181905550806005858154811061288557612885613174565b90600052602060002090600602016005018190555050505050565b600080600583815481106128b6576128b6613174565b600091825260208083208684526007825260408085203386529092529220600560069092029092019081015460038301549193506128fa9142916117c59190612b52565b949350505050565b60006125c8828461308c565b60006125c8828461306a565b6040516001600160a01b03831660248201526044810182905261299290849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166001600160e01b031990931692909217909152612be6565b505050565b6009546129db5760405162461bcd60e51b81526020600482015260126024820152711b9bdd081a5b9a5d1a5b1a5e9959081e595d60721b6044820152606401610614565b6002546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b158015612a1f57600080fd5b505afa158015612a33573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a579190612ec3565b905080156129925780821115612ac657600254612a7e906001600160a01b0316848361291a565b826001600160a01b03167f90e90785750b5c9aca0f1af9a2b927e14effbf15cebb417b0f8f416ce8c0e2f282604051612ab991815260200190565b60405180910390a2505050565b600254612add906001600160a01b0316848461291a565b826001600160a01b03167f90e90785750b5c9aca0f1af9a2b927e14effbf15cebb417b0f8f416ce8c0e2f283604051612ab991815260200190565b60055460005b81811015612b4257612b2f81611404565b5080612b3a8161312d565b915050612b1e565b5050565b60006125c882846130ea565b60006125c88284613052565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516001600160a01b03808516602483015283166044820152606481018290526113fe9085906323b872dd60e01b90608401612946565b6000612c3b826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612cb89092919063ffffffff16565b8051909150156129925780806020019051810190612c599190612e8d565b6129925760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610614565b60606128fa848460008585843b612d115760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610614565b600080866001600160a01b03168587604051612d2d9190612fc3565b60006040518083038185875af1925050503d8060008114612d6a576040519150601f19603f3d011682016040523d82523d6000602084013e612d6f565b606091505b50915091506121c782828660608315612d895750816125c8565b825115612d995782518084602001fd5b8160405162461bcd60e51b81526004016106149190612fdf565b80356001600160a01b03811681146118c257600080fd5b600060208284031215612ddc57600080fd5b6125c882612db3565b600080600060608486031215612dfa57600080fd5b612e0384612db3565b95602085013595506040909401359392505050565b60008060208385031215612e2b57600080fd5b823567ffffffffffffffff80821115612e4357600080fd5b818501915085601f830112612e5757600080fd5b813581811115612e6657600080fd5b8660208260051b8501011115612e7b57600080fd5b60209290920196919550909350505050565b600060208284031215612e9f57600080fd5b81516125c88161318a565b600060208284031215612ebc57600080fd5b5035919050565b600060208284031215612ed557600080fd5b5051919050565b60008060408385031215612eef57600080fd5b82359150612eff60208401612db3565b90509250929050565b600080600080600060a08688031215612f2057600080fd5b85359450612f3060208701612db3565b935060408601359250606086013591506080860135612f4e8161318a565b809150509295509295909350565b600080600060608486031215612f7157600080fd5b8335925060208401359150612f8860408501612db3565b90509250925092565b60008060008060808587031215612fa757600080fd5b5050823594602084013594506040840135936060013592509050565b60008251612fd5818460208701613101565b9190910192915050565b6020815260008251806020840152612ffe816040850160208701613101565b601f01601f19169190910160400192915050565b6000808212826001600160ff1b03038413811516156130335761303361315e565b600160ff1b839003841281161561304c5761304c61315e565b50500190565b600082198211156130655761306561315e565b500190565b60008261308757634e487b7160e01b600052601260045260246000fd5b500490565b60008160001904831182151516156130a6576130a661315e565b500290565b60008083128015600160ff1b8501841216156130c9576130c961315e565b836001600160ff1b030183138116156130e4576130e461315e565b50500390565b6000828210156130fc576130fc61315e565b500390565b60005b8381101561311c578181015183820152602001613104565b838111156113fe5750506000910152565b60006000198214156131415761314161315e565b5060010190565b634e487b7160e01b600052600160045260246000fd5b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b801515811461268557600080fdfe4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572a164736f6c6343000807000a

Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Validator ID :
0 FTM

Amount Staked
0

Amount Delegated
0

Staking Total
0

Staking Start Epoch
0

Staking Start Time
0

Proof of Importance
0

Origination Score
0

Validation Score
0

Active
0

Online
0

Downtime
0 s
Address Amount claimed Rewards Created On Epoch Created On
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.