DeFi产品都需要具备哪些基础技术能力呢?
首先是资产发行技术能力(如:ERC-20方式)资产跨链导入技术能力(比如:公证人机制、侧链/中继机制、哈希锁定、支持WalletConnect协议等。并且积极导入MPC应用场景),目前以太坊因为具备ERC-20资产发行技术能力,在DeFi占比达到95%左右,一骑绝尘。
其次是基于智能合约的借贷、资管、券商、交易所、保险服务生态,DeFi协议的本质就是债权合约,权益合约和其他衍生品合约的组合,设计协议的合理性和经济学效应。
再者是用户最熟悉的生态入口,也就是我们常用的APP或者网站等。入口的建设极其重要,因为用户感知不到技术的“好坏”,只有从可视化产品中得到判断。
最后是ORACLE预言机建设,外部ORACLE预言机接入。预言机是区块链智能合约与外部世界交互的接口,可以查找和验证真实世界的数据,并以加密的方式将信息提交给智能合约使用,所以预言机对于DeFi来说至关重要。
随着技术实力的额提升,我们可以将DeFi的演化分为三个阶段:
第一阶段,提供基础模块服务。包括:发行类,包括资产创建,资产跨链导入,流动性挖矿等(如:LAT、ETH、BTC、USDT导入资产管理);借贷质押支付类(基础商业银行服务);支持基础DeFi协议标准、以及生态类。
第二阶段,提供金融服务。如:资管类(各类工具群,包括钱包等);交易类(流动性促进,信用交易等券商服务等);固收类及衍生品交易类。
第三阶段,为生态完善。包括:DeFi保险作为风险对冲入场、可靠可信的资讯数据聚合服务广泛应用(ORACLE的基础)、基于分布式数字身份的信用管理类服务等。
合约源代码
constructor(address ownerAddress) public {
levelPrice[1] = 0.025 ether;
for (uint8 i = 2; i <= LAST_LEVEL; i++) {
levelPrice[i] = levelPrice[i-1] * 2;
}
owner = ownerAddress;
User memory user = User({
id: 1,
referrer: address(0),
partnersCount: uint(0)
});
users[ownerAddress] = user;
idToAddress[1] = ownerAddress;
for (uint8 i = 1; i <= LAST_LEVEL; i++) {
users[ownerAddress].activeX3Levels[i] = true;
users[ownerAddress].activeX6Levels[i] = true;
}
userIds[1] = ownerAddress;
}
function() external payable {
if(msg.data.length == 0) {
return registration(msg.sender, owner);
}
registration(msg.sender, bytesToAddress(msg.data));
}
function registrationExt(address referrerAddress) external payable {
registration(msg.sender, referrerAddress);
}
function buyNewLevel(uint8 matrix, uint8 level) external payable {
require(isUserExists(msg.sender), "user is not exists. Register first.");
require(matrix == 1 || matrix == 2, "invalid matrix");
require(msg.value == levelPrice[level], "invalid price");
require(level > 1 && level <= LAST_LEVEL, "invalid level");
if (matrix == 1) {
require(!users[msg.sender].activeX3Levels[level], "level already activated");
if (users[msg.sender].x3Matrix[level-1].blocked) {
users[msg.sender].x3Matrix[level-1].blocked = false;
}
address freeX3Referrer = findFreeX3Referrer(msg.sender, level);
users[msg.sender].x3Matrix[level].currentReferrer = freeX3Referrer;
users[msg.sender].activeX3Levels[level] = true;
updateX3Referrer(msg.sender, freeX3Referrer, level);
emit Upgrade(msg.sender, freeX3Referrer, 1, level);
} else {
require(!users[msg.sender].activeX6Levels[level], "level already activated");
if (users[msg.sender].x6Matrix[level-1].blocked) {
users[msg.sender].x6Matrix[level-1].blocked = false;
}
address freeX6Referrer = findFreeX6Referrer(msg.sender, level);
users[msg.sender].activeX6Levels[level] = true;
updateX6Referrer(msg.sender, freeX6Referrer, level);
emit Upgrade(msg.sender, freeX6Referrer, 2, level);
}
}
function registration(address userAddress, address referrerAddress) private {
require(msg.value == 0.05 ether, "registration cost 0.05");
require(!isUserExists(userAddress), "user exists");
require(isUserExists(referrerAddress), "referrer not exists");
uint32 size;
assembly {
size := extcodesize(userAddress)
}
require(size == 0, "cannot be a contract");
User memory user = User({
id: lastUserId,
referrer: referrerAddress,
partnersCount: 0
});
users[userAddress] = user;
idToAddress[lastUserId] = userAddress;
users[userAddress].referrer = referrerAddress;
users[userAddress].activeX3Levels[1] = true;
users[userAddress].activeX6Levels[1] = true;
userIds[lastUserId] = userAddress;
lastUserId++;
users[referrerAddress].partnersCount++;
address freeX3Referrer = findFreeX3Referrer(userAddress, 1);
users[userAddress].x3Matrix[1].currentReferrer = freeX3Referrer;
updateX3Referrer(userAddress, freeX3Referrer, 1);
updateX6Referrer(userAddress, findFreeX6Referrer(userAddress, 1), 1);
emit Registration(userAddress, referrerAddress, users[userAddress].id, users[referrerAddress].id);
}
function updateX3Referrer(address userAddress, address referrerAddress, uint8 level) private {
users[referrerAddress].x3Matrix[level].referrals.push(userAddress);
if (users[referrerAddress].x3Matrix[level].referrals.length < 3) {
emit NewUserPlace(userAddress, referrerAddress, 1, level, uint8(users[referrerAddress].x3Matrix[level].referrals.length));
return sendETHDividends(referrerAddress, userAddress, 1, level);
}
emit NewUserPlace(userAddress, referrerAddress, 1, level, 3);
//close matrix
users[referrerAddress].x3Matrix[level].referrals = new address[](0);
if (!users[referrerAddress].activeX3Levels[level+1] && level != LAST_LEVEL) {
users[referrerAddress].x3Matrix[level].blocked = true;
}