Contract Functions
Token Exchange
function buy(address ipId) public payable {
require(checkListed(ipId), "IP is not listed");
uint256 price = getBuyPrice(ipId);
(uint256 creatorFee, uint256 protocolFee, uint256 totalFee) = _calcTradingFees(price);
uint256 priceAfterFee = price + totalFee;
require(msg.value >= priceAfterFee, "Insufficient payment");
uint256 assetId = ipIdToAssetId[ipId];
totalSupply[assetId] += 1;
poolLiquidity[assetId] += price;
_mint(msg.sender, assetId, 1, "");
emit Trade(TradeType.Buy, ipId, assetId, msg.sender, 1, price, creatorFee);
(bool creatorFeeSent, ) = payable(storyHelper.getIpOwner(ipId)).call{ value: creatorFee }("");
require(creatorFeeSent, "Failed to send creator fee");
if (protocolFee > 0) {
(bool protocolFeeSent, ) = payable(owner()).call{ value: protocolFee }("");
require(protocolFeeSent, "Failed to send protocol fee");
}
if (msg.value > priceAfterFee) {
(bool refunded, ) = payable(msg.sender).call{ value: msg.value - priceAfterFee }("");
require(refunded, "Failed to refund excess payment");
}
}Remix
Price Curve
Last updated