深入解析Pancakeswap Prediction|博饼预测玩法

常见问题

  • 领取奖金有时间限制吗?
    没有时间限制,可以在任何时间来领取。
  • 利息是如何计算的?
    上行池的支付比率=两个池的总价值÷上行池的价值
    下行池的支付比率=两个池的总价值÷下行池的价值
    例如,如果一轮的下线有15BNB,而总奖金池为150BNB,下线支付比率将为(150/15)=10x。
    支付金额=支付比率×头寸×(1-库务费)
    在上述情况下,如果一轮以下跌结果结束,如果您向下跌头寸承诺2 BNB,您将获得(2*10)×(1-0.03)=19.4 BNB的赔付。您的利润将为174亿英镑(19.4-2英镑)。
    财政费目前设定为3%:这可能会有变化,将在PancakeSwap的官方沟通渠道上公布。国库费用用于回购和烧掉蛋糕代币。
  • 手续费是如何计算的?
    每轮总奖金的3%将被燃烧。

代码解析

    /**
     * @notice 看跌
     * @param epoch: epoch 轮数
     * @param amount: 代币竞猜数量 wei
     */
    function betBear(uint256 epoch, uint256 amount) external whenNotPaused nonReentrant notContract {
        require(epoch == currentEpoch, "Bet is too early/late");
        require(_bettable(epoch), "Round not bettable");
        require(amount >= minBetAmount, "Bet amount must be greater than minBetAmount");
        require(ledger[epoch][msg.sender].amount == 0, "Can only bet once per round");
        //对面无竞猜 不可下注
        if(roundsNumber[epoch][Position.Bear] > 0 && (roundsNumber[epoch][Position.Bull] == 0)){
            return;
        }
        //代币转入合约中
        tokens.safeTransferFrom(msg.sender, address(this), amount);
        //更新竞猜对象内容
        Round storage round = rounds[epoch];
        round.totalAmount = round.totalAmount + amount;
        round.bearAmount = round.bearAmount + amount;

        // 更新用户数据
        BetInfo storage betInfo = ledger[epoch][msg.sender];
        betInfo.position = Position.Bear;
        betInfo.amount = amount;
        userRounds[msg.sender].push(epoch);

        player[msg.sender] = true;
        roundsNumber[epoch][Position.Bear] += 1;
		//记录日志
        emit BetBear(msg.sender, epoch, amount);
    }
	/**
     * @notice 看涨
     * @param epoch: 轮数
     * @param amount: 代币竞猜数量 wei
     */
    function betBull(uint256 epoch, uint256 amount) external payable whenNotPaused nonReentrant notContract {
        require(epoch == currentEpoch, "Bet is too early/late");
        require(_bettable(epoch), "Round not bettable");
        require(amount >= minBetAmount, "Bet amount must be greater than minBetAmount");
        require(ledger[epoch][msg.sender].amount == 0, "Can only bet once per round");
        if(roundsNumber[epoch][Position.Bull] > 0 && (roundsNumber[epoch][Position.Bear] == 0)){
            return;
        }

        tokens.safeTransferFrom(msg.sender, address(this), amount);
        Round storage round = rounds[epoch];
        round.totalAmount = round.totalAmount + amount;
        round.bullAmount = round.bullAmount + amount;

        // Update user data
        BetInfo storage betInfo = ledger[epoch][msg.sender];
        betInfo.position = Position.Bull;
        betInfo.amount = amount;
        userRounds[msg.sender].push(epoch);
        
        player[msg.sender] = true;
        roundsNumber[epoch][Position.Bull] += 1;

        emit BetBull(msg.sender, epoch, amount);
    }
	/**
     * @notice 开始下一轮n,锁定第n-1轮的价格,结束第n-2轮
     * @dev 只有管理员账户可以操作
     */
    function executeRound() external whenNotPaused onlyOperator {
        require(
            genesisStartOnce && genesisLockOnce,
            "Can only run after genesisStartRound and genesisLockRound is triggered"
        );

        (uint80 currentRoundId, int256 currentPrice) = _getPriceFromOracle();

        oracleLatestRoundId = uint256(currentRoundId);

        // CurrentEpoch refers to previous round (n-1)
        _safeLockRound(currentEpoch, currentRoundId, currentPrice);
        _safeEndRound(currentEpoch - 1, currentRoundId, currentPrice);
        _calculateRewards(currentEpoch - 1);

        // Increment currentEpoch to current round (n)
        currentEpoch = currentEpoch + 1;
        _safeStartRound(currentEpoch);
    }
	/**
     * @notice 开始回合
     * @dev Callable by admin or operator
     */
    function genesisStartRound() external whenNotPaused onlyOperator {
        require(!genesisStartOnce, "Can only run genesisStartRound once");

        currentEpoch = currentEpoch + 1;
        _startRound(currentEpoch);
        genesisStartOnce = true;
    }
	/**
     * @notice 领取全部奖励
     * @param epochs: 有奖励轮数数组
     */
    function claim(uint256[] calldata epochs) external nonReentrant notContract {
        uint256 reward; // Initializes reward
        uint256 rcm1Amt;
        uint256 rcm2Amt;
        uint256 rcm3Amt;
        uint256 marketAmt;

        for (uint256 i = 0; i < epochs.length; i++) {
            require(rounds[epochs[i]].times.startTimestamp != 0, "Round has not started");
            require(block.timestamp > rounds[epochs[i]].times.closeTimestamp, "Round has not ended");

            uint256 addedReward = 0;

            // 竞猜有效
            if (rounds[epochs[i]].oracleCalled) {
                // 猜对
                if(claimable(epochs[i], msg.sender)){
                    Round memory round = rounds[epochs[i]];
                    //轮空
                    if(round.isBet){
                        require(refundable(epochs[i], msg.sender), "Not eligible for refund");
                        addedReward = ledger[epochs[i]][msg.sender].amount;
                        recommendOtherAmt[msg.sender] = ledger[epochs[i]][msg.sender].amount * failureFee / 10000;
                    }else{
                        addedReward = (ledger[epochs[i]][msg.sender].amount * round.rewardAmount) / round.rewardBaseCalAmount;
                        marketAmt = addedReward / (10000 - totalFee) * marketFee / 10000000;
                        rcm1Amt = addedReward / (10000 - totalFee) * recommend1Fee / 10000000;
                        rcm2Amt = addedReward / (10000 - totalFee) * recommend2Fee / 10000000;
                        rcm3Amt = addedReward / (10000 - totalFee) * recommend3Fee / 10000000;
                        distributionProfit(rcm1Amt, rcm2Amt, rcm3Amt, marketAmt, msg.sender);
                    }
                //猜错    
                }else if(isLotteryFailure(epochs[i], msg.sender)){
                    recommendOtherAmt[msg.sender] = ledger[epochs[i]][msg.sender].amount * failureFee / 10000;
                }
            }
            // 竞猜无效 退还金额
            else {
                require(refundable(epochs[i], msg.sender), "Not eligible for refund");
                addedReward = ledger[epochs[i]][msg.sender].amount;
            }

            ledger[epochs[i]][msg.sender].claimed = true;
            reward += addedReward;

            emit Claim(msg.sender, epochs[i], addedReward);
        }
		//发放收益
        if (reward > 0) {
            _safeTransfeTokens(tokens, address(msg.sender), reward);
        }
    }

其他问题

  • 如果没有人进入相反的预测会发生什么?
    如果一轮中只有一方持仓,那么该方就输了,损失的资金将被送到总奖池。
    例如:用户A进入向上位置,没有其他人进入向下位置。用户A输了,并且没有相反的头寸可供支付奖金。资金被送到总奖池。
  • 如果锁定价格和收盘价格完全相同,会发生什么情况?
    在锁定价格与收盘价格完全相同的极少数情况下,没有人获胜,所有进入头寸的资金都将被送到财政部,用于烧掉蛋糕回购。
  • 我可以改变或取消我的竞猜吗?
    不,一旦你进入一个位置,你就不能改变方向

笔者整理了常见的一些智能合约并进行分类,如有需要请自取。
点击跳转

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zgsdzczh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值