Skip to content
Verified contractExactMIT

Bouts

Address0x47e3657addcf8ca8d136e46fcf654890c1a12488
Balance

0 ETH

 

Transactions

6

 

Compiler

solc 0.7.6

 

Same code

Only this contract

 

Details

Compiler
solc 0.7.6+commit.7338295f
Language
solidity
Optimization
No
EVM version
istanbul
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
12,399,478
Creation transaction
0x0f839263d6…8fcbe9b8cb

3 files

Bouts.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma abicoder v2;

import "./IERC20.sol";
import "./SafeMath.sol";

contract Bouts {
    using SafeMath for uint256;

    struct CompensationPlan {
        uint8 id;
        uint256 differentialDirectIncome;
        uint256 commissionable;
        uint256 points;
        uint256 stakingPeriod;
        uint256 minimumAmount;
        uint256 maximumAmount;
        uint256 rateOfInterest;
    }

    struct BonusPlan {
        uint8 level;
        uint8 bonus;
        uint8 points;
    }

    struct PackageLimit {
        uint256 investmentLimit;
        uint256 investmentMade;
        uint256 timeLimit;
        uint256 limit;
        uint256 dailyLimit;
        uint256 nextReset;
        uint256[] lastSubscribers;
    }

    struct Subscription {
        bool isActive;
        uint8 compensationPlanID;
        uint256 startTime;
        uint256 lastWithdrawedTime;
        uint256 amountInvested;
        uint256 amountWithdrawed;
    }

    struct User {
        uint256 id;
        uint256 leadershipDevelopmentBonus;
        uint256 earlyBirdIncentive;
        uint256 reward;
        address referrer;
        uint256 points;
        uint256 levelBonus;
        uint256 withdrawedROI;
        uint256 totalDirectIncome;
        uint256 scholarshipFund;
        uint256 differentialDirectIncome;
        uint256[2] paymentTimestamp;
        Subscription[] subscriptions;
    }

    event UserRegistered(
        uint256 id,
        address user,
        address referrer,
        uint256 timestamp
    );
    event UserSubscribed(
        address userAddress,
        uint8 compensationPlanID,
        uint256 amount,
        uint256 timestamp
    );
    event DifferentialDirectIncomeSent(
        address referee,
        address referrer,
        uint256 amount,
        uint256 level,
        uint256 timestamp
    );
    event EarlyBirdIncentiveSent(
        address from,
        address to,
        uint256 amount,
        uint256 timestamp
    );
    event LeadershipDevelopmentBonus(
        address to,
        uint256 amount,
        uint256 timestamp
    );
    event LevelBonusSent(
        address referee,
        address referrer,
        uint256 amount,
        uint256 level,
        uint256 timestamp
    );
    event UserWithdrawed(address user, uint256 amount, uint256 timestamp);
    event Points(address user, uint256 points, uint256 timestamp);
    event ScholarshipFund(
        address owner,
        address user,
        uint256 amount,
        uint256 timestamp
    );
    event RewardsAdded(
        address userAddress,
        uint256 planID,
        uint256 amount,
        uint256 timestamp
    );

    uint256 public userIdCounter;
    address public OWNER;
    address public TOKEN_CONTRACT;
    address public SCHOLARSHIP_ADDRESS;
    address public REFERRAL_BONUS_ADDRESS;
    address public REWARDS_BONUS_ADDRESS;
    address public STAKING_BONUS_ADDRESS;
    address public LEVEL_BONUS_ADDRESS;
    uint8 private ROI_MULTIPLIER;
    uint256 private DAYS_IN_SECONDS;

    mapping(uint8 => CompensationPlan) public compensationPlans;
    mapping(uint8 => BonusPlan) public bonusPlan;
    mapping(uint8 => PackageLimit) public packageLimit;
    mapping(address => User) public users;
    mapping(uint256 => address) public userIds;

    constructor(address boutsTokenContract) {
        ROI_MULTIPLIER = 100;
        DAYS_IN_SECONDS = 1 days;
        TOKEN_CONTRACT = boutsTokenContract;
        OWNER = msg.sender;

        SCHOLARSHIP_ADDRESS = 0xd12F6103902B4375fa91320Ee6f86bdA33Ed11Bb;
        REFERRAL_BONUS_ADDRESS = 0x64B434265CF6DF7B4276CA1E063A187010c24470;
        REWARDS_BONUS_ADDRESS = 0xe94e9B674b5833B4C6cBfA96bDB9FF4A76774f44;
        STAKING_BONUS_ADDRESS = 0xDEd48389ebaaD8085bD9B1f5e438f14A021348fB;
        LEVEL_BONUS_ADDRESS = 0x8d333A890DFABD4faC5604136F819CaE79dCe488;

        _addCompensationPlans();
        _addLevelBonus();
        _addPackageLimits();

        users[msg.sender].id = ++userIdCounter;
        userIds[userIdCounter] = msg.sender;
        users[msg.sender].subscriptions.push(
            Subscription(true, 4, block.timestamp, 0, 0, 0)
        );
        users[msg.sender].paymentTimestamp[0] = block.timestamp;
        users[msg.sender].paymentTimestamp[1] =
            block.timestamp +
            10000 *
            DAYS_IN_SECONDS;
    }

    function subscribe(uint8 compensationPlanID, address referrer) public {
        User storage user = users[msg.sender];
        require(
            compensationPlans[compensationPlanID].minimumAmount != 0,
            "Invalid plan id"
        );

        if (user.id == 0) {
            if (referrer == address(0)) referrer = OWNER;
            require(users[referrer].id != 0, "Invaild Referrer");
            userIdCounter = userIdCounter.add(1);
            user.id = userIdCounter;
            user.referrer = referrer;
            userIds[userIdCounter] = msg.sender;
            user.paymentTimestamp[0] = block.timestamp;
            user.paymentTimestamp[1] = user.paymentTimestamp[0].add(
                DAYS_IN_SECONDS.mul(30)
            );
            emit UserRegistered(
                userIdCounter,
                msg.sender,
                referrer,
                block.timestamp
            );
        }
        if (user.subscriptions.length != 0)
            require(
                user.subscriptions[user.subscriptions.length - 1]
                    .compensationPlanID < compensationPlanID,
                "Cannot subscribe plan"
            );

        IERC20 boutsToken = IERC20(TOKEN_CONTRACT);
        uint256 amount = boutsToken.allowance(msg.sender, address(this));
        // uint256 amount = compensationPlans[compensationPlanID].minimumAmount;
        _checkPackageLimit(compensationPlanID, amount);
        require(
            amount >= compensationPlans[compensationPlanID].minimumAmount &&
                amount <= compensationPlans[compensationPlanID].maximumAmount,
            "Invalid staking amount"
        );

        Subscription memory subscription;

        subscription.compensationPlanID = compensationPlanID;
        subscription.startTime = block.timestamp;
        subscription.amountInvested = amount;
        subscription.isActive = true;
        user.subscriptions.push(subscription);

        boutsToken.transferFrom(msg.sender, address(this), amount);
        users[user.referrer].points = users[user.referrer].points.add(
            compensationPlans[compensationPlanID].points
        );

        _giveDifferentialDirectIncome(user, amount);
        _giveEarlyBirdIncentive(users[user.referrer]);

        emit UserSubscribed(
            msg.sender,
            compensationPlanID,
            amount,
            block.timestamp
        );
        emit Points(
            user.referrer,
            users[user.referrer].points,
            block.timestamp
        );
    }

    function withdraw(
        bool rateOfInterest,
        bool differentialDirectIncome,
        bool earlyBirdIncentive,
        bool leadershipDevelopmentBonus,
        bool levelBonus,
        bool rewards
    ) public {
        User storage user = users[msg.sender];
        IERC20 boutsToken = IERC20(TOKEN_CONTRACT);
        uint256 amount;
        if (differentialDirectIncome) {
            amount = amount.add(user.differentialDirectIncome);
            boutsToken.transferFrom(
                REFERRAL_BONUS_ADDRESS,
                msg.sender,
                user.differentialDirectIncome
            );
            user.differentialDirectIncome = 0;
        }
        if (earlyBirdIncentive) {
            amount = amount.add(user.earlyBirdIncentive);
            boutsToken.transferFrom(
                REWARDS_BONUS_ADDRESS,
                msg.sender,
                user.earlyBirdIncentive
            );
            user.earlyBirdIncentive = 0;
        }
        if (leadershipDevelopmentBonus) {
            amount = amount.add(user.leadershipDevelopmentBonus);
            boutsToken.transferFrom(
                REWARDS_BONUS_ADDRESS,
                msg.sender,
                user.leadershipDevelopmentBonus
            );
            user.leadershipDevelopmentBonus = 0;
        }
        if (rateOfInterest) {
            (uint256 roi, uint256 principalAmount) =
                calculateRateOfInterest(msg.sender);
            amount = amount.add(roi);
            user.withdrawedROI = user.withdrawedROI.add(roi);
            _shareLevelIncome(roi);

            boutsToken.transferFrom(STAKING_BONUS_ADDRESS, msg.sender, roi);

            if (principalAmount != 0) {
                user.withdrawedROI = user.withdrawedROI.add(principalAmount);
                boutsToken.transfer(msg.sender, principalAmount);
            }
        }
        if (levelBonus) {
            amount = amount.add(user.levelBonus);
            boutsToken.transferFrom(
                LEVEL_BONUS_ADDRESS,
                msg.sender,
                user.reward
            );
            user.levelBonus = 0;
        }
        if (rewards) {
            amount = amount.add(user.reward);
            boutsToken.transferFrom(
                REWARDS_BONUS_ADDRESS,
                msg.sender,
                user.reward
            );
            user.reward = 0;
        }

        require(amount != 0, "Invalid withdrawal amount");

        // boutsToken.transfer(msg.sender, amount);

        emit UserWithdrawed(msg.sender, amount, block.timestamp);
    }

    function giveLeadershipDevelopmentBonus(
        address[] calldata userAddresses,
        uint256[] calldata amount
    ) public {
        require(msg.sender == OWNER, "Only owner can call this function");
        for (uint256 index = 0; index < userAddresses.length; index++) {
            users[userAddresses[index]].leadershipDevelopmentBonus = amount[
                index
            ];

            emit LeadershipDevelopmentBonus(
                userAddresses[index],
                amount[index],
                block.timestamp
            );
        }
    }

    function getPaymentTimestamp(address userAddress)
        public
        view
        returns (uint256, uint256)
    {
        return (
            users[userAddress].paymentTimestamp[0],
            users[userAddress].paymentTimestamp[1]
        );
    }

    function getSubscriptions(address userAddress)
        public
        view
        returns (Subscription[] memory)
    {
        return users[userAddress].subscriptions;
    }

    function donateToScholarshipFund() public {
        User storage user = users[msg.sender];
        user.paymentTimestamp[0] = block.timestamp;
        user.paymentTimestamp[1] = user.paymentTimestamp[0].add(
            DAYS_IN_SECONDS.mul(30)
        );

        IERC20 boutsToken = IERC20(TOKEN_CONTRACT);
        uint256 amount = boutsToken.allowance(msg.sender, address(this));
        require(amount >= user.scholarshipFund, "Invalid scholarship amount");
        boutsToken.transferFrom(msg.sender, SCHOLARSHIP_ADDRESS, amount);

        emit ScholarshipFund(
            SCHOLARSHIP_ADDRESS,
            msg.sender,
            user.scholarshipFund,
            block.timestamp
        );

        user.scholarshipFund = 0;
    }

    function _addCompensationPlans() private {
        compensationPlans[1] = CompensationPlan(
            1,
            5,
            5,
            1,
            200 * DAYS_IN_SECONDS,
            1000e18,
            10000e18 - 1,
            uint256(ROI_MULTIPLIER).div(2)
        );

        compensationPlans[2] = CompensationPlan(
            2,
            10,
            10,
            2,
            300 * DAYS_IN_SECONDS,
            10000e18,
            50000e18 - 1,
            uint256(ROI_MULTIPLIER).mul(3).div(4)
        );

        compensationPlans[3] = CompensationPlan(
            3,
            15,
            15,
            4,
            400 * DAYS_IN_SECONDS,
            50000e18,
            100000e18 - 1,
            ROI_MULTIPLIER
        );

        compensationPlans[4] = CompensationPlan(
            4,
            20,
            20,
            8,
            500 * DAYS_IN_SECONDS,
            100000e18,
            150000e18,
            uint256(ROI_MULTIPLIER).mul(5).div(4)
        );
    }

    function _addLevelBonus() private {
        bonusPlan[1] = BonusPlan(1, 20, 2);
        bonusPlan[2] = BonusPlan(2, 5, 4);
        bonusPlan[3] = BonusPlan(3, 5, 12);
        bonusPlan[4] = BonusPlan(4, 5, 20);
        bonusPlan[5] = BonusPlan(5, 5, 26);
        bonusPlan[6] = BonusPlan(6, 5, 38);
        bonusPlan[7] = BonusPlan(7, 5, 46);
        bonusPlan[8] = BonusPlan(8, 5, 62);
        bonusPlan[9] = BonusPlan(9, 5, 78);
        bonusPlan[10] = BonusPlan(10, 5, 94);
        bonusPlan[11] = BonusPlan(11, 20, 108);
    }

    function _addPackageLimits() private {
        uint256 nextReset =
            block.timestamp + (block.timestamp % DAYS_IN_SECONDS);
        packageLimit[1].investmentLimit = 10e25;
        packageLimit[1].timeLimit = block.timestamp + 400 * DAYS_IN_SECONDS;
        packageLimit[2].investmentLimit = 75e24;
        packageLimit[2].timeLimit = block.timestamp + 300 * DAYS_IN_SECONDS;
        packageLimit[3].dailyLimit = 20;
        packageLimit[3].investmentLimit = 5e25;
        packageLimit[3].timeLimit = block.timestamp + 200 * DAYS_IN_SECONDS;
        packageLimit[3].nextReset = nextReset;
        packageLimit[4].dailyLimit = 5;
        packageLimit[4].investmentLimit = 25e24;
        packageLimit[4].timeLimit = block.timestamp + 100 * DAYS_IN_SECONDS;
        packageLimit[4].nextReset = nextReset;
    }

    function _checkPackageLimit(uint8 compensationPlanID, uint256 amount)
        private
    {
        require(
            packageLimit[compensationPlanID].investmentLimit >=
                packageLimit[compensationPlanID].investmentMade + amount,
            "Cannot stake tokens, limit exceeded"
        );
        require(
            packageLimit[compensationPlanID].timeLimit >= block.timestamp,
            "Investment time exceeded"
        );

        if (compensationPlanID > 2)
            require(
                _checkDailyPackageLimit(compensationPlanID),
                "Daily plan subscription limit reached"
            );

        packageLimit[compensationPlanID].investmentMade += amount;
    }

    function _checkDailyPackageLimit(uint8 compensationPlanID)
        private
        returns (bool)
    {
        PackageLimit storage package = packageLimit[compensationPlanID];

        if (block.timestamp >= package.nextReset) {
            uint256 nextReset =
                block.timestamp + (block.timestamp % DAYS_IN_SECONDS);
            package.nextReset = nextReset;
            delete package.lastSubscribers;
        }

        if (package.lastSubscribers.length < package.dailyLimit) {
            package.lastSubscribers.push(block.timestamp);
            return true;
        }

        return false;
    }

    function _giveDifferentialDirectIncome(
        User memory user,
        uint256 totalAmount
    ) private {
        User storage referrer = users[user.referrer];
        bool[4] memory distributedPlans;
        uint256 referrerDifferentialDirectIncome;
        uint256 commissionableLeft;
        uint8 planID = 0;
        uint256 amount = 0;
        bool paymentMissed = false;
        address referrerAddress;

        for (uint256 index = 0; index < user.subscriptions.length; index++)
            if (
                commissionableLeft <
                compensationPlans[user.subscriptions[index].compensationPlanID]
                    .commissionable
            )
                commissionableLeft = compensationPlans[
                    user.subscriptions[index].compensationPlanID
                ]
                    .commissionable;

        for (
            uint256 index = 1;
            commissionableLeft > 0 &&
                !(distributedPlans[0] == true &&
                    distributedPlans[1] == true &&
                    distributedPlans[2] == true &&
                    distributedPlans[3] == true);
            index++
        ) {
            if (referrer.referrer == address(0)) {
                amount = amount.add(
                    totalAmount.mul(commissionableLeft).div(100)
                );

                referrer.differentialDirectIncome = referrer
                    .differentialDirectIncome
                    .add(amount);

                referrer.scholarshipFund = referrer.scholarshipFund.add(
                    amount.div(10)
                );

                referrer.totalDirectIncome = referrer.totalDirectIncome.add(
                    amount
                );
                emit DifferentialDirectIncomeSent(
                    userIds[user.id],
                    userIds[referrer.id],
                    amount,
                    index,
                    block.timestamp
                );
                commissionableLeft = 0;
                break;
            }

            for (
                uint256 planIdIndex;
                planIdIndex < referrer.subscriptions.length;
                planIdIndex++
            )
                if (
                    planID <
                    referrer.subscriptions[planIdIndex].compensationPlanID
                )
                    planID = referrer.subscriptions[planIdIndex]
                        .compensationPlanID;

            planID--;
            if (distributedPlans[planID]) continue;
            for (
                uint256 subscriptionIndex = 0;
                subscriptionIndex < referrer.subscriptions.length;
                subscriptionIndex++
            ) {
                if (
                    compensationPlans[
                        referrer.subscriptions[subscriptionIndex]
                            .compensationPlanID
                    ]
                        .differentialDirectIncome >
                    referrerDifferentialDirectIncome
                )
                    referrerDifferentialDirectIncome = compensationPlans[
                        referrer.subscriptions[subscriptionIndex]
                            .compensationPlanID
                    ]
                        .differentialDirectIncome;
            }

            if (
                referrer.paymentTimestamp[1] - referrer.paymentTimestamp[0] >
                30 * DAYS_IN_SECONDS
            ) {
                paymentMissed = true;
                referrerAddress = userIds[referrer.id];
                emit DifferentialDirectIncomeSent(
                    userIds[user.id],
                    userIds[referrer.id],
                    0,
                    index,
                    block.timestamp
                );
                referrer = users[OWNER];
            }

            if (commissionableLeft <= referrerDifferentialDirectIncome) {
                amount = amount.add(
                    totalAmount.mul(commissionableLeft).div(100)
                );
                referrer.differentialDirectIncome = referrer
                    .differentialDirectIncome
                    .add(amount);
                referrer.scholarshipFund = referrer.scholarshipFund.add(
                    amount.div(10)
                );
                referrer.totalDirectIncome = referrer.totalDirectIncome.add(
                    amount
                );

                emit DifferentialDirectIncomeSent(
                    userIds[user.id],
                    userIds[referrer.id],
                    amount,
                    index,
                    block.timestamp
                );
                commissionableLeft = 0;
            } else {
                amount = amount.add(
                    totalAmount.mul(referrerDifferentialDirectIncome).div(100)
                );
                referrer.differentialDirectIncome = referrer
                    .differentialDirectIncome
                    .add(amount);
                referrer.scholarshipFund = referrer.scholarshipFund.add(
                    amount.div(10)
                );

                referrer.totalDirectIncome = referrer.totalDirectIncome.add(
                    amount
                );

                emit DifferentialDirectIncomeSent(
                    userIds[user.id],
                    userIds[referrer.id],
                    amount,
                    index,
                    block.timestamp
                );
                commissionableLeft = commissionableLeft.sub(
                    referrerDifferentialDirectIncome
                );
            }

            distributedPlans[planID] = true;

            if (paymentMissed) {
                referrerAddress = userIds[referrer.id];
                referrer = users[referrerAddress];
            }

            if (referrer.referrer == address(0)) break;
            referrer = users[referrer.referrer];
            amount = 0;
        }
    }

    function _giveEarlyBirdIncentive(User storage user) private {
        if (
            block.timestamp.sub(user.subscriptions[0].startTime) <=
            60 * DAYS_IN_SECONDS
        )
            if (user.points >= 94 && user.earlyBirdIncentive != 2500e18) {
                user.earlyBirdIncentive = 2500e18;
                emit EarlyBirdIncentiveSent(
                    msg.sender,
                    userIds[user.id],
                    user.earlyBirdIncentive,
                    block.timestamp
                );
            } else if (
                user.points >= 78 && user.earlyBirdIncentive != 1000e18
            ) {
                user.earlyBirdIncentive = 1000e18;
                emit EarlyBirdIncentiveSent(
                    msg.sender,
                    userIds[user.id],
                    user.earlyBirdIncentive,
                    block.timestamp
                );
            }
    }

    function _shareLevelIncome(uint256 amount_) private {
        User storage user = users[users[msg.sender].referrer];
        uint256 amount;
        uint8 planID = 0;

        for (
            uint256 planIdIndex;
            planIdIndex < user.subscriptions.length;
            planIdIndex++
        ) {
            if (planID < user.subscriptions[planIdIndex].compensationPlanID)
                planID = user.subscriptions[planIdIndex].compensationPlanID;
        }

        for (uint8 index = 1; index <= 11; index++) {
            if (index == 11 && planID != 4) continue;
            amount = amount_.mul(bonusPlan[index].bonus).div(100);
            if (
                user.points < bonusPlan[index].points ||
                user.paymentTimestamp[1] - user.paymentTimestamp[0] >
                30 * DAYS_IN_SECONDS
            ) {
                users[OWNER].levelBonus = users[OWNER].levelBonus.add(amount);
                users[OWNER].scholarshipFund = users[OWNER].scholarshipFund.add(
                    amount.div(10)
                );

                emit LevelBonusSent(
                    msg.sender,
                    OWNER,
                    amount,
                    index,
                    block.timestamp
                );
                emit LevelBonusSent(
                    msg.sender,
                    userIds[user.id],
                    0,
                    index,
                    block.timestamp
                );
            } else {
                user.levelBonus = user.levelBonus.add(amount);
                user.scholarshipFund = user.scholarshipFund.add(amount.div(10));

                emit LevelBonusSent(
                    msg.sender,
                    userIds[user.id],
                    amount,
                    index,
                    block.timestamp
                );
            }

            amount = 0;
            if (user.referrer == address(0)) break;
            user = users[user.referrer];
        }
    }

    function giveRewards(
        address[] calldata userAddress,
        uint256[] calldata planID,
        uint256[] calldata rewards
    ) public {
        require(msg.sender == OWNER, "Only owner can call this function");

        for (uint256 index = 0; index < userAddress.length; index++) {
            users[userAddress[index]].reward = users[userAddress[index]]
                .reward
                .add(rewards[index]);
            emit RewardsAdded(
                userAddress[index],
                planID[index],
                rewards[index],
                block.timestamp
            );
        }
    }

    function calculateRateOfInterest(address userAddress)
        public
        returns (uint256, uint256)
    {
        uint256 time = 0;
        uint256 totalAmount = 0;
        uint256 principalAmount = 0;

        User memory user = users[userAddress];

        for (uint256 index = 0; index < user.subscriptions.length; index++) {
            Subscription storage subscription =
                users[userIds[user.id]].subscriptions[index];
            if (!subscription.isActive) continue;

            if (subscription.lastWithdrawedTime == 0) {
                time = block.timestamp.sub(subscription.startTime);
                if (
                    time >
                    compensationPlans[subscription.compensationPlanID]
                        .stakingPeriod
                )
                    time = compensationPlans[subscription.compensationPlanID]
                        .stakingPeriod;
            } else {
                time = subscription.lastWithdrawedTime - subscription.startTime;
                if (
                    block.timestamp.sub(subscription.lastWithdrawedTime).add(
                        time
                    ) >
                    compensationPlans[subscription.compensationPlanID]
                        .stakingPeriod
                )
                    time =
                        compensationPlans[subscription.compensationPlanID]
                            .stakingPeriod -
                        time;
                else
                    time = block.timestamp.sub(subscription.lastWithdrawedTime);
            }
            time = time.div(DAYS_IN_SECONDS);
            uint256 amount = 0;
            amount = subscription.amountInvested;
            amount = amount
                .mul(time)
                .mul(
                compensationPlans[subscription.compensationPlanID]
                    .rateOfInterest
            )
                .div(ROI_MULTIPLIER)
                .div(100);

            if (
                subscription.startTime.add(
                    compensationPlans[subscription.compensationPlanID]
                        .stakingPeriod
                ) <= block.timestamp
            ) {
                principalAmount = principalAmount.add(
                    subscription.amountInvested
                );
                subscription.isActive = false;
            }
            subscription.amountWithdrawed = subscription.amountWithdrawed.add(
                amount
            );
            subscription.lastWithdrawedTime = block.timestamp;
            totalAmount = totalAmount.add(amount);
        }
        return (totalAmount, principalAmount);
    }
}

IERC20.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

interface IERC20 {
    function totalSupply() external view returns (uint256);

    function balanceOf(address account) external view returns (uint256);

    function transfer(address recipient, uint256 amount)
        external
        returns (bool);

    function allowance(address owner, address spender)
        external
        view
        returns (uint256);

    function approve(address spender, uint256 amount) external returns (bool);

    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );
}

SafeMath.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
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) {
        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) {
        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) {
        // 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) {
        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) {
        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) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }

    /**
     * @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) {
        require(b <= a, "SafeMath: subtraction overflow");
        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) {
        if (a == 0) return 0;
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }

    /**
     * @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. 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) internal pure returns (uint256) {
        require(b > 0, "SafeMath: division by zero");
        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) {
        require(b > 0, "SafeMath: modulo by zero");
        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) {
        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.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryDiv}.
     *
     * 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) {
        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) {
        require(b > 0, errorMessage);
        return a % b;
    }
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "evmVersion": "istanbul",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.