DeFi decentralized exchange system development technology

What is a decentralized exchange?
In a decentralized exchange, the user's assets are directly hosted in the user's own wallet, which greatly reduces the risk of user assets being lost due to theft or runaway of the exchange. The matching transactions completed through smart contracts and the settlement and clearing completed on the chain not only improve transparency, but also greatly reduce the dependence on the central medium.
In fact, these are only decentralized exchanges in a narrow sense. In a broad sense, decentralized exchanges include all decentralized value and asset exchange methods. Due to the lack of trust, in many existing trading scenarios, various forms of centralized exchanges are required to provide trust guarantees. The blockchain technology will reduce the cost of trust by building invisible decentralized exchanges, and gradually reshape the old value exchange system.
Advantages of decentralized exchanges:
The real holders of digital assets are the users themselves, who have absolute ownership and control over their digital assets, and will not lose their assets due to exchanges such as theft, ensuring the digital assets’ safety.
Through open source smart contracts, asset custody, matching transactions, and asset clearing are all placed on the blockchain.
Using smart contracts to implement a decentralized and trustless transaction mechanism solves the risks of internal operation risks, business ethics risks, asset embezzlement and other risks that seriously affect user asset security caused by human factors in centralized exchanges.
The user's custody assets can be transferred freely without anyone's approval, and the asset freedom is higher.
Since the user's account key is in his own hands, technically, hacker attacks have been changed from centralized attacks on exchanges to attacks on decentralized personal accounts. The decline in profit margins has resulted in an increase in relative security.
In the field of blockchain, the pursuit of "decentralization" is a beautiful vision. Decentralized exchanges are still in the early stage of development. The mature model requires market exploration and technical experiments.
However, there are still many problems that need to be solved in order to truly become a decentralized exchange, such as the simplification of the exchange method and the underlying technology of the blockchain.

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");

Guess you like

Origin blog.csdn.net/m0_51754086/article/details/109259205