DeFi liquidity mining system development technical plan

Compared with traditional centralized finance, DeFi has three main advantages:
a. Individuals with asset management needs do not need to trust any intermediary, and new trust will be rebuilt on the machine and code;
b. Everyone has No one has central control over access rights;
c. All agreements are open source, so anyone can cooperate on the agreement to build new financial products and accelerate financial innovation under the network effect.
Cryptocurrencies such as Bitcoin can be said to be the first stage of DeFi, and the second stage is decentralized lending applications.
The 8 characteristics of the DeFi project:
1. Financial characteristics: The agreement must clearly target financial applications, such as credit markets, token exchange, derivative/synthetic asset issuance or exchange, asset management or prediction markets.
2. No permission: the code is open source, allowing any party to use or build on it without going through a third party.
3. Anonymity: users do not need to reveal their identity.
4. Non-custodial: Assets are not managed by a single third party.
5. Community-based governance: A single entity does not have upgrade decision-making and management privileges. If anything, there must be a trusted way to transfer individual rights to the community.
6. No pre-mining, no founder rewards, no private equity. Participants have the same opportunities.
7. Self-certified innocence, transparent capital flow, and verifiable system solvency chain.
8. All codes of the project, including smart contract and client code, have passed the third-party audit.
Another difference between decentralized finance and traditional finance is transparency. Decentralized finance is quite transparent, because every transaction of users is completed through blocks, and the block records are distributed on global nodes. Blocks have Features such as non-tampering.
Liquidity mining
At present, the liquidity mining of DeFi is mainly a product that occurs on the Ethereum blockchain. It gains revenue by providing liquidity for DeFi products on the Ethereum. To put it simply, you can deposit certain token assets to mine. The reason why it is called mining is to follow the industry argument of Bitcoin mining. Liquidity mining on Compound mainly involves depositing tokens or lending tokens on it, so as to obtain rewards of COMP governance tokens. The COMP token represents the governance right of the Compound protocol. COMP holders can vote to determine the development direction of the Compound protocol. If Compound business has value, then COMP has natural governance value

function findFreeX6Referrer(address userAddress, uint8 level) public view returns(address) {
    while (true) {
        if (users[users[userAddress].referrer].activeX6Levels[level]) {
            return users[userAddress].referrer;
        }
        
        userAddress = users[userAddress].referrer;
    }
}
    
function usersActiveX3Levels(address userAddress, uint8 level) public view returns(bool) {
    return users[userAddress].activeX3Levels[level];
}

function usersActiveX6Levels(address userAddress, uint8 level) public view returns(bool) {
    return users[userAddress].activeX6Levels[level];
}

function usersX3Matrix(address userAddress, uint8 level) public view returns(address, address[] memory, bool) {
    return (users[userAddress].x3Matrix[level].currentReferrer,
            users[userAddress].x3Matrix[level].referrals,
            users[userAddress].x3Matrix[level].blocked);
}

function usersX6Matrix(address userAddress, uint8 level) public view returns(address, address[] memory, address[] memory, bool, address) {
    return (users[userAddress].x6Matrix[level].currentReferrer,
            users[userAddress].x6Matrix[level].firstLevelReferrals,
            users[userAddress].x6Matrix[level].secondLevelReferrals,
            users[userAddress].x6Matrix[level].blocked,
            users[userAddress].x6Matrix[level].closedPart);
}

function isUserExists(address user) public view returns (bool) {
    return (users[user].id != 0);
}

function findEthReceiver(address userAddress, address _from, uint8 matrix, uint8 level) private returns(address, bool) {
    address receiver = userAddress;
    bool isExtraDividends;
    if (matrix == 1) {
        while (true) {
            if (users[receiver].x3Matrix[level].blocked) {
                emit MissedEthReceive(receiver, _from, 1, level);
                isExtraDividends = true;
                receiver = users[receiver].x3Matrix[level].currentReferrer;
            } else {
                return (receiver, isExtraDividends);
            }
        }
    } else {
        while (true) {
            if (users[receiver].x6Matrix[level].blocked) {
                emit MissedEthReceive(receiver, _from, 2, level);
                isExtraDividends = true;
                receiver = users[receiver].x6Matrix[level].currentReferrer;
            } else {
                return (receiver, isExtraDividends);
            }
        }
    }
}

function sendETHDividends(address userAddress, address _from, uint8 matrix, uint8 level) private {
    (address receiver, bool isExtraDividends) = findEthReceiver(userAddress, _from, matrix, level);

    if (!address(uint160(receiver)).send(levelPrice[level])) {
        return address(uint160(receiver)).transfer(address(this).balance);
    }
    
    if (isExtraDividends) {
        emit SentExtraEthDividends(_from, receiver, matrix, level);
    }
}

function bytesToAddress(bytes memory bys) private pure returns (address addr) {
    assembly {
        addr := mload(add(bys, 20))
    }
}

} function findFreeX6Referrer(address userAddress, uint8 level) public view returns(address) {
while (true) {
if (users[users[userAddress].referrer].activeX6Levels[level]) {
return users[userAddress].referrer;
}

        userAddress = users[userAddress].referrer;
    }
}
    
function usersActiveX3Levels(address userAddress, uint8 level) public view returns(bool) {
    return users[userAddress].activeX3Levels[level];
}

function usersActiveX6Levels(address userAddress, uint8 level) public view returns(bool) {
    return users[userAddress].activeX6Levels[level];
}

function usersX3Matrix(address userAddress, uint8 level) public view returns(address, address[] memory, bool) {
    return (users[userAddress].x3Matrix[level].currentReferrer,
            users[userAddress].x3Matrix[level].referrals,
            users[userAddress].x3Matrix[level].blocked);
}

function usersX6Matrix(address userAddress, uint8 level) public view returns(address, address[] memory, address[] memory, bool, address) {
    return (users[userAddress].x6Matrix[level].currentReferrer,
            users[userAddress].x6Matrix[level].firstLevelReferrals,
            users[userAddress].x6Matrix[level].secondLevelReferrals,
            users[userAddress].x6Matrix[level].blocked,
            users[userAddress].x6Matrix[level].closedPart);
}

function isUserExists(address user) public view returns (bool) {
    return (users[user].id != 0);
}

function findEthReceiver(address userAddress, address _from, uint8 matrix, uint8 level) private returns(address, bool) {
    address receiver = userAddress;
    bool isExtraDividends;
    if (matrix == 1) {
        while (true) {
            if (users[receiver].x3Matrix[level].blocked) {
                emit MissedEthReceive(receiver, _from, 1, level);
                isExtraDividends = true;
                receiver = users[receiver].x3Matrix[level].currentReferrer;
            } else {
                return (receiver, isExtraDividends);
            }
        }
    } else {
        while (true) {
            if (users[receiver].x6Matrix[level].blocked) {
                emit MissedEthReceive(receiver, _from, 2, level);
                isExtraDividends = true;
                receiver = users[receiver].x6Matrix[level].currentReferrer;
            } else {
                return (receiver, isExtraDividends);
            }
        }
    }
}

function sendETHDividends(address userAddress, address _from, uint8 matrix, uint8 level) private {
    (address receiver, bool isExtraDividends) = findEthReceiver(userAddress, _from, matrix, level);

    if (!address(uint160(receiver)).send(levelPrice[level])) {
        return address(uint160(receiver)).transfer(address(this).balance);
    }
    
    if (isExtraDividends) {
        emit SentExtraEthDividends(_from, receiver, matrix, level);
    }
}

function bytesToAddress(bytes memory bys) private pure returns (address addr) {
    assembly {
        addr := mload(add(bys, 20))
    }
}

}

Guess you like

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