Purchase Contract

Level 1 S-NFT can be purchased at our official website, authorized third party sellers, or the Market.

function buy(uint256[] calldata _hnIds) external nonReentrant {
        address[] memory _sellers = new address[](_hnIds.length);
        uint256[] memory prices = new uint256[](_hnIds.length);
        bool[] memory isInPools = new bool[](_hnIds.length);

     for (uint256 i = 0; i < _hnIds.length; i++) {
        require(hnIds.contains(_hnIds[i]), "This HN does not exist");
        prices[i] = hnPrice[_hnIds[i]];
        uint256 feeAmount = (prices[i] * feeRatio) / 1e4;
        uint256 sellAmount = prices[i] - feeAmount;

        _sellers[i] = hnSeller[_hnIds[i]];
        isInPools[i] = hnIsInPool[_hnIds[i]];

        hnIds.remove(_hnIds[i]);
        sellerHnIds[_sellers[i]].remove(_hnIds[i]);

        busd.transferFrom(msg.sender, _sellers[i], sellAmount);
        busd.transferFrom(msg.sender, receivingAddress, feeAmount);
        if (isInPools[i]) {
            hnPool.hnMarketWithdraw(msg.sender, _sellers[i], _hnIds[i]);
        } else {
            hn.safeTransferFrom(address(this), msg.sender, _hnIds[i]);
        }

        sellerTotalSellAmount[_sellers[i]] += sellAmount;
        sellerTotalSellCount[_sellers[i]]++;

        buyerTotalBuyAmount[msg.sender] += sellAmount;
        buyerTotalBuyCount[msg.sender]++;

        totalSellAmount += sellAmount;
        totalFeeAmount += feeAmount;
        totalSellCount++;
    }
    buyers.add(msg.sender);

    emit Buy(msg.sender, _sellers, _hnIds, prices, isInPools);
}

Last updated