{"content":{"title":"深入分析Friend.Tech项目","body":"Friend.Tech是一个新兴的区块链社交平台，在短时间内引起了广泛关注；该平台的注册需要绑定X(twitter) 账户，每个账户都有其「社交价值」，可以购买自己和别人的账户股权，当你持有别人账户的股权时，就可以和此账户聊天。\r\n\r\n\\\r\n**本文仅从技术层面分析下 [friend.tech](http://friend.tech) 项目，不构成任何投资建议。**\r\n\r\n\\\r\nfriend.tech是Base链上的的SocialFi项目，在Base浏览器上可以找到项目的[合约代码](https://basescan.org/address/0xCF205808Ed36593aa40a44F10c7f7C2F67d4A4d4#code)：\r\n\r\n合约名称：**FriendtechSharesV1**\r\n\r\n合约地址：**0xCF205808Ed36593aa40a44F10c7f7C2F67d4A4d4**\r\n\r\n### 主要变量\r\n\r\n```solidity\r\naddress public protocolFeeDestination; // 协议收费地址\r\nuint256 public protocolFeePercent; // 协议收费比率\r\nuint256 public subjectFeePercent; // 股权持有者收费比率\r\n```\r\n\r\n每次买入卖出一个账户的股权（key），账户和项目方都要收手续费，目前根据链上数据可知手续费都是5% 。 \r\n\r\n[![手续费](https://img.learnblockchain.cn/attachments/2023/12/Z1jLBF0x658181c50a2c1.png)](https://basescan.org/tx/0x98e5b449b3545a0d35f683f3df9c7b7658a0ece7a8ec479c946ebdbde2315814)\r\n\r\n\r\n\r\n### 事件\r\n\r\n```solidity\r\nevent Trade(address trader, address subject, bool isBuy, uint256 shareAmount, uint256 ethAmount, uint256 protocolEthAmount, uint256 subjectEthAmount, uint256 supply);\r\n```\r\n\r\n每次买卖行为都会触发交易事件，交易事件记录了买方和卖方的地址，买入key的数量和使用的eth数量，以及收取的手续费和交易后key的供应量。 可以在区块中监听此事件来进行链上数据分析。\r\n\r\n### 获取价格\r\n\r\n```solidity\r\nfunction getPrice(uint256 supply, uint256 amount) public pure returns (uint256) {\r\n    uint256 sum1 = supply == 0 ? 0 : (supply - 1 )* (supply) * (2 * (supply - 1) + 1) / 6;\r\n    uint256 sum2 = supply == 0 && amount == 1 ? 0 : (supply - 1 + amount) * (supply + amount) * (2 * (supply - 1 + amount) + 1) / 6;\r\n    uint256 summation = sum2 - sum1;\r\n    return summation * 1 ether / 16000;\r\n}\r\n```\r\n\r\n其中supply表示key的供应量，amount表示要交易的key数量。可以从公式中看到当买key的第一个份额是免费的（合约要求key的拥有账户才能买第一个份额）。\r\n\r\n\r\n![购买第一个份额](https://img.learnblockchain.cn/attachments/2023/12/y2eri2mE658182672bf77.png)\r\n\r\n\\\r\n对于sum1和sum2的计算用到了前n个数的平方和公式： 推导见[这里](https://www.bilibili.com/video/BV1QS4y1i7hz/?vd_source=97409223eab1f5918d64a93735c63e46)。\r\n\r\n$$\r\nsum=\\frac{n \\cdot (n + 1) \\cdot (2n + 1)}{6}\r\n$$\r\n\r\n对于价格的计算：\r\n\r\n$$\r\nprice=\\frac{\\text{summation}}{16000} \\times 1 \\, \\text{ether}\r\n$$\r\n\r\n假设amount为1，则summation=sum2-sum1=n^2：\r\n\r\n$$\r\nprice=\\frac{n^2}{16000} \\times 1 \\, \\text{ether}\r\n$$\r\n\r\n后面乘 1ether 是使用因子使结果转换为wei，可以简化为：\r\n\r\n$$\r\nprice=\\frac{n^2}{16000}\r\n$$\r\n\r\n\\\r\n这就是项目的经济模型，即 Price in ETH = supply^ 2 / 16000。在 friend.tech的交互中也验证了这一点。\r\n\r\n<div align=\"center\">\r\n    \r\n![2023-12-19_16-22.png](https://img.learnblockchain.cn/attachments/2023/12/ivnwTZfE65818329da41c.png)\r\n</div>\r\n    \r\n### 经济模型\r\n\r\n每组key的价格都会随着持有人的增加而呈现“指数增长”，所以当key被购买或者出售时，key的价格都会产生波动。price = supply^2 是一个指数函数，而16000只是为了使价格增长平缓一点，从而更符合市场的匹配关系。\r\n\r\n<div align=\"center\">\r\n    \r\n[![经济模型](https://img.learnblockchain.cn/attachments/2023/12/wr4JleIs6581837b1ce9c.png \"数据来源\")](https://onedrive.live.com/view.aspx?resid=C078415A103A3F40%211094&authkey=!ANE0-sqb5hAftiI)\r\n*数据来源：https://onedrive.live.com/view.aspx?resid=C078415A103A3F40%211094&authkey=!ANE0-sqb5hAftiI*\r\n</div>\r\n\r\n\\\r\n随着发行股份总量的不断增长，买卖股份之间的价差净值会越来越大，但价差率（价差/卖价）会越来越小。价差存在的原因并不复杂，股份的增长是从 0 开始，因而必然是先有买后有卖，卖方总是要落后于买方的。在如下函数中体现：\r\n```solidity\r\nfunction getBuyPrice(address sharesSubject, uint256 amount) public view returns (uint256) {\r\n    return getPrice(sharesSupply[sharesSubject], amount);                      \r\n}                                                                              \r\n                                                                                   \r\nfunction getSellPrice(address sharesSubject, uint256 amount) public view returns (uint256) {\r\n    return getPrice(sharesSupply[sharesSubject] - amount, amount);             \r\n}\r\n```\r\n\r\n可以看出买key时候的supply是当前key的供应量，而卖key时的supply=当前的供应量-卖出的数量；\r\n\r\n\\\r\n不同供应量对应的价格关系：\r\n<div align=\"center\">\r\n    \r\n[![zpp68n5f9wustw3e!webp.webp](https://img.learnblockchain.cn/attachments/2023/12/rtmF8DAC6581851a03a0a.webp)](https://onedrive.live.com/view.aspx?resid=C078415A103A3F40%211094&authkey=!ANE0-sqb5hAftiI)\r\n*数据来源：https://onedrive.live.com/view.aspx?resid=C078415A103A3F40%211094&authkey=!ANE0-sqb5hAftiI*\r\n</div>\r\n    \r\n\\\r\n使用公式进行验证，假设某个key的供应量为 supply=100, 购买量为 amount=1,  计算价格：\r\n\r\n$$\r\nsum1=\\frac{{(100 - 1) \\cdot 100 \\cdot (2 \\cdot (100 - 1) + 1)}}{6} = 328350\r\n$$\r\n\r\n$$\r\nsum2=\\frac{{100 \\cdot 101 \\cdot (2 \\cdot 100 + 1)}}{6}=338350\r\n$$\r\n\r\nsummation = sum2 - sum1 = 10000，则价格为：\r\n\r\n$$\r\n\\text{price} = \\frac{\\text{summation} \\times 1 \\text{ ether}}{16000} = \\frac{10000 \\times 1}{16000} = 0.625\r\n$$\r\n\r\n\\\r\n![经济模型](https://img.learnblockchain.cn/attachments/2023/12/qhbBVT3665818621ab7a3.png)\r\n*数据来源:：https://www.desmos.com/calculator/clnecohl2s*\r\n\r\n### 购买\r\n\r\n```solidity\r\nfunction buyShares(address sharesSubject, uint256 amount) public payable {   \r\n    uint256 supply = sharesSupply[sharesSubject]; \r\n    // 要求key的拥有账户购买第一个份额                          \r\n    require(supply > 0 || sharesSubject == msg.sender, \"Only the shares' subject can buy the first share\");\r\n    uint256 price = getPrice(supply, amount);   \r\n    // 计算协议收取的手续费                            \r\n    uint256 protocolFee = price * protocolFeePercent / 1 ether;    \r\n    // 计算key拥有者账户收取的手续费         \r\n    uint256 subjectFee = price * subjectFeePercent / 1 ether;   \r\n    // 检查交易金额            \r\n    require(msg.value >= price + protocolFee + subjectFee, \"Insufficient payment\");\r\n    // 更新购买者的持有量\r\n    sharesBalance[sharesSubject][msg.sender] = sharesBalance[sharesSubject][msg.sender] + amount;\r\n    // 更新key的供应量\r\n    sharesSupply[sharesSubject] = supply + amount;\r\n\t  // 触发交易事件                          \r\n    emit Trade(msg.sender, sharesSubject, true, amount, price, protocolFee, subjectFee, supply + amount);\r\n    // 转账手续费给协议账户\r\n    (bool success1, ) = protocolFeeDestination.call{value: protocolFee}(\"\");\r\n    // 转账手续费给key的拥有者账户\r\n    (bool success2, ) = sharesSubject.call{value: subjectFee}(\"\");          \r\n    require(success1 && success2, \"Unable to send funds\");                  \r\n }\r\n```\r\n\r\n\r\n### 售出\r\n\r\n```solidity\r\nfunction sellShares(address sharesSubject, uint256 amount) public payable { \r\n    uint256 supply = sharesSupply[sharesSubject]; \r\n    // 检查购买量                          \r\n    require(supply > amount, \"Cannot sell the last share\");                 \r\n    uint256 price = getPrice(supply - amount, amount);\r\n    // 计算协议收取的手续费                      \r\n    uint256 protocolFee = price * protocolFeePercent / 1 ether;  \r\n    // 计算key拥有者账户收取的手续费           \r\n    uint256 subjectFee = price * subjectFeePercent / 1 ether;  \r\n    // 检查交易金额               \r\n    require(sharesBalance[sharesSubject][msg.sender] >= amount, \"Insufficient shares\");\r\n    // 更新购买者的持有量\r\n    sharesBalance[sharesSubject][msg.sender] = sharesBalance[sharesSubject][msg.sender] - amount;\r\n    // 更新key的供应量\r\n    sharesSupply[sharesSubject] = supply - amount;   \r\n    // 触发交易事件                       \r\n    emit Trade(msg.sender, sharesSubject, false, amount, price, protocolFee, subjectFee, supply - amount);\r\n    // 转账售卖收入到卖出者钱包\r\n    (bool success1, ) = msg.sender.call{value: price - protocolFee - subjectFee}(\"\");\r\n    // 转账手续费给协议账户\r\n    (bool success2, ) = protocolFeeDestination.call{value: protocolFee}(\"\");\r\n    // 转账手续费给key的拥有者账户\r\n    (bool success3, ) = sharesSubject.call{value: subjectFee}(\"\");          \r\n    require(success1 && success2 && success3, \"Unable to send funds\");      \r\n}\r\n```\r\n\r\n从购买和售出函数中可以看出在 Trade 事件函数签名中，供应量supply是当次交易之后的key供应量，在做链上数据分析时注意甄别。\r\n\r\n\\\r\n\\\r\n### 总结\r\n本文撰写时friend.tech项目的链上数据：\r\n\r\n[![数据分析](https://img.learnblockchain.cn/attachments/2023/12/nkqrscIP658187087143c.png)](https://dune.com/cryptokoryo/friendtech)\r\n*数据来源：https://dune.com/cryptokoryo/friendtech*\r\n\r\n截至12月19日18: 00 ，friend.tech交易量已超过 1.5 万 ETH，累计完成了超过 1247万笔交易。在深入探讨了friend.tech项目的智能合约逻辑和经济模型后，可以看到这个项目在Web3领域展现出了显著的创新性和潜力。通过巧妙地结合区块链技术和社交媒体的动态，friend.tech不仅为用户提供了一个独特的社交平台，还开辟了一条新的路径，能够在去中心化环境中实现社交影响力的货币化。不过从10月开始交易量逐渐减少，也标示着项目的热度的逐渐降低，决定其产品是否可持续的因素是有影响力的用户是否愿意持续经营以创造价值，并最终转化为向外的能量，最终形成破圈效应。期待其后续的表现，期待更多的SocialFi赛道优质项目。\r\n\r\n\\\r\n**声明：本文只做技术分享，不构成任何投资建议。**"},"author":{"user":"https://learnblockchain.cn/people/10520","address":null},"history":"bafkreidmsvwlb4nh6k7rur3z6j3xghjuthmizbhufqsvikwiu4kshtzc4q","timestamp":1703158680,"version":1}