Debit and credit voucher:When you deposit a token in Compound,you will get a credit voucher cToken.cToken is the ownership of the user's pledge token.You can exchange the original token and withdraw the corresponding profits in the Compound agreement.
LP voucher:The user will get the LP voucher Uni-XXX by depositing the token into Uniswap.The LP voucher is the ownership and usufruct certificate of the user's market making.
With these vouchers,users can obtain profit distribution,making the tokens in their hands continue to grow.Liquidity mining goes further,adding new revenue incentives on the basis of the original revenue,which can motivate users to use the DeFi application.
部署的合约:Multicall.sol
/**
*Submitted for verification at Etherscan.io on 2019-06-10
*/
pragma solidity>=0.5.0;
pragma experimental ABIEncoderV2;
//SPDX-License-Identifier:GPL-3.0
///title Multicall-Aggregate results from multiple read-only function calls
///author Michael Elliot<mike makerdao.com>
///author Joshua Levine<joshua makerdao.com>
///author Nick Johnson<arachnid notdot.net>
contract Multicall{
struct Call{
address target;
bytes callData;
}
function aggregate(Call[]memory calls)public returns(uint256 blockNumber,bytes[]memory returnData){
blockNumber=block.number;
returnData=new bytes[](calls.length);
for(uint256 i=0;i<calls.length;i++){
(bool success,bytes memory ret)=calls<i>.target.call(calls<i>.callData);
require(success);
returnData<i>=ret;
}
}
//Helper functions
function getEthBalance(address addr)public view returns(uint256 balance){
balance=addr.balance;
}
function getBlockHash(uint256 blockNumber)public view returns(bytes32 blockHash){
blockHash=blockhash(blockNumber);
}
function getLastBlockHash()public view returns(bytes32 blockHash){
blockHash=blockhash(block.number-1);
}
function getCurrentBlockTimestamp()public view returns(uint256 timestamp){
timestamp=block.timestamp;
}
function getCurrentBlockDifficulty()public view returns(uint256 difficulty){
difficulty=block.difficulty;
}
function getCurrentBlockGasLimit()public view returns(uint256 gaslimit){
gaslimit=block.gaslimit;
}
function getCurrentBlockCoinbase()public view returns(address coinbase){
coinbase=block.coinbase;
}
}
js调用合约
//引入web3
const Web3=require('web3');
const web3=new Web3('http://192.168.75.129:8545');
//部署合约的abi
const abi=[
{
"constant":false,
"inputs":[
{
"components":[
{
"internalType":"address",
"name":"target",
"type":"address"
},
{
"internalType":"bytes",
"name":"callData",
"type":"bytes"
}
],
"internalType":"struct Multicall.Call[]",
"name":"calls",
"type":"tuple[]"
}
],
"name":"aggregate",
"outputs":[
{
"internalType":"uint256",
"name":"blockNumber",
"type":"uint256"
},
{
"internalType":"bytes[]",
"name":"returnData",
"type":"bytes[]"
}
],
"payable":false,
"stateMutability":"nonpayable",
"type":"function"
},
{
"constant":true,
"inputs":[
{
"internalType":"uint256",
"name":"blockNumber",
"type":"uint256"
}
],
"name":"getBlockHash",
"outputs":[
{
"internalType":"bytes32",
"name":"blockHash",
"type":"bytes32"
}
],
"payable":false,
"stateMutability":"view",
"type":"function"
},
{
"constant":true,
"inputs":[],
"name":"getCurrentBlockCoinbase",
"outputs":[
{
"internalType":"address",
"name":"coinbase",
"type":"address"
}
],
"payable":false,
"stateMutability":"view",
"type":"function"
},
{
"constant":true,
"inputs":[],
"name":"getCurrentBlockDifficulty",
"outputs":[
{
"internalType":"uint256",
"name":"difficulty",
"type":"uint256"
}
],
"payable":false,
"stateMutability":"view",
"type":"function"
},
{
"constant":true,
"inputs":[],
"name":"getCurrentBlockGasLimit",
"outputs":[
{
"internalType":"uint256",
"name":"gaslimit",
"type":"uint256"
}
],
"payable":false,
"stateMutability":"view",
"type":"function"
},
{
"constant":true,
"inputs":[],
"name":"getCurrentBlockTimestamp",
"outputs":[
{
"internalType":"uint256",
"name":"timestamp",
"type":"uint256"
}
],
"payable":false,
"stateMutability":"view",
"type":"function"
},
{
"constant":true,
"inputs":[
{
"internalType":"address",
"name":"addr",
"type":"address"
}
],
"name":"getEthBalance",
"outputs":[
{
"internalType":"uint256",
"name":"balance",
"type":"uint256"
}
],
"payable":false,
"stateMutability":"view",
"type":"function"
},
{
"constant":true,
"inputs":[],
"name":"getLastBlockHash",
"outputs":[
{
"internalType":"bytes32",
"name":"blockHash",
"type":"bytes32"
}
],
"payable":false,
"stateMutability":"view",
"type":"function"
}
];
//部署到链上的合约的地址
const address='0xd573A1f062751A4f947f1769B5D78c1815420bf9';
//通过new web3.eth.Contract(abi,address)动态创建一个合约实例
let MyContract=new web3.eth.Contract(abi,address);
//getEthBalance方法是合约中的方法,methods为调取合约方法的内置方法
MyContract.methods.getEthBalance('0x88ded3010c9e9b2b2d1914b07c0d674281952d19').call().then(console.log);