对FILLocked合约进行操作,登陆Metamask以后,可以通过Read和Write功能对自己的账户进行操作。 以下是关于FILLocked核心功能解析 1: 基本参数: 一年的区块数量:uint256 year = 20*60*24*365; 合约总封存数量:uint256 public lockedAmount ; 2:封存对象 struct Locked { address useraddress; uint256 depositNumber; uint256 amount; uint256 price; uint256 withdrawNumber; uint256 withdrawedNumber; } 3:设置价格参数地址 function setFilPriceAddr(address _filPriceAddr) public returns (bool) { require(isAuthListed[msg.sender]==true,"Unauthorized operation account"); filPriceAddr = _filPriceAddr; return true; } 4:查询我的质押 function getMyDeposits(uint256 blockNumber)public view returns(Locked memory){ string memory indexs=getAddNumberStr(msg.sender, blockNumber); Locked memory lock= deposits[indexs]; return lock; } 5: 解除封存 function withdraw(uint blockNumber)public returns(bool){ IERC20 filCoin = IERC20(filAddress); string memory indexs=getAddNumberStr(msg.sender, blockNumber); //查询封存数据 Locked memory lock= deposits[getAddNumberStr(msg.sender, blockNumber)]; //如果余额为0,说明已经解锁 require(lock.amount>0,"The balance is 0, and this pledge has been withdrawn"); //提现解锁条件 require((block.number > lock.withdrawNumber||price > lock.price*35/10),"Pledge not yet due"); //365days or 3.5price //修改解锁数据 uint256 amount= lock.amount; //用户提现后,锁仓余额修改为0 lock.amount=0; //标注提现区块高度 lock.withdrawedNumber=block.number; deposits[indexs]=lock; //解锁 filCoin.transfer(msg.sender,amount); //修改总封存数量 lockedAmount=lockedAmount-amount; return true; } 6: 封存 function deposit(address user,uint amount) public returns (bool) { require(isAuthListed[msg.sender]==true,"Unauthorized operation account"); //记录封存用户地址 locked.useraddress=user; //记录封存时间 locked.depositNumber=block.number; //记录封存数量 locked.amount=amount; //记录最早解锁区块高度 locked.withdrawNumber=block.number+year; deposits[getAddNumberStr(user, block.number)]=locked; //增加封存总数量 lockedAmount=lockedAmount+amount; return true; } 7: 组装索引 function getAddNumberStr(address sender,uint256 blockNumber) private pure returns( string memory){ return string(abi.encodePacked(Strings.toHexString(uint160(sender), 20),"-",Strings.toString(blockNumber))); } 8:获取余额 function getTokenBalance(address contractAddress, address accountAddress) private view returns (uint256) { ERC20 ercToken = ERC20(contractAddress); return ercToken.balanceOf(accountAddress); } 以上就是FILLocked的主要功能,在接下来的文章中,我们将逐一分析FIL2的其他合约,共同验证FIL2如何通过开源技术保证资金的安全和规则的公平。 来源:金色财经lg...