From df9bb4f66157ef91273509065aee00541a07de59 Mon Sep 17 00:00:00 2001 From: zpykillccc <79955764+zpykillccc@users.noreply.github.com> Date: Tue, 23 Nov 2021 20:02:16 +0800 Subject: [PATCH 01/11] Add files via upload --- ABI.json | 193 ++++++++++++++++++++++++------------------------------ Lock.sol | 125 +++++++++++++++++++---------------- Readme.md | 51 ++++++++++++++- 3 files changed, 203 insertions(+), 166 deletions(-) diff --git a/ABI.json b/ABI.json index cea65a9..80662e5 100644 --- a/ABI.json +++ b/ABI.json @@ -1,4 +1,9 @@ [ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, { "anonymous": false, "inputs": [ @@ -37,85 +42,6 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [ - { - "internalType": "address", - "name": "addr", - "type": "address" - }, - { - "internalType": "uint64", - "name": "timeSlice", - "type": "uint64" - }, - { - "internalType": "uint64", - "name": "count", - "type": "uint64" - }, - { - "internalType": "string", - "name": "txid", - "type": "string" - } - ], - "name": "lockLinear", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "addr", - "type": "address" - } - ], - "name": "transferLock", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "paramOwner", - "type": "address" - } - ], - "name": "transferOwner", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "withdrawAll", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "withdrawAmount", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, { "inputs": [], "name": "getAllCount", @@ -155,6 +81,29 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "addr", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "string", + "name": "txid", + "type": "string" + } + ], + "name": "lock540", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, { "inputs": [ { @@ -170,6 +119,11 @@ ], "name": "queryAll", "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, { "components": [ { @@ -191,16 +145,6 @@ "internalType": "uint64", "name": "startTime", "type": "uint64" - }, - { - "internalType": "uint64", - "name": "slice", - "type": "uint64" - }, - { - "internalType": "uint64", - "name": "count", - "type": "uint64" } ], "internalType": "struct Lock.QueryResult[]", @@ -221,6 +165,11 @@ ], "name": "queryAny", "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, { "components": [ { @@ -242,16 +191,6 @@ "internalType": "uint64", "name": "startTime", "type": "uint64" - }, - { - "internalType": "uint64", - "name": "slice", - "type": "uint64" - }, - { - "internalType": "uint64", - "name": "count", - "type": "uint64" } ], "internalType": "struct Lock.QueryResult", @@ -292,16 +231,6 @@ "internalType": "uint64", "name": "startTime", "type": "uint64" - }, - { - "internalType": "uint64", - "name": "slice", - "type": "uint64" - }, - { - "internalType": "uint64", - "name": "count", - "type": "uint64" } ], "internalType": "struct Lock.QueryResult", @@ -311,5 +240,51 @@ ], "stateMutability": "view", "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "addr", + "type": "address" + } + ], + "name": "transferLock", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "paramOwner", + "type": "address" + } + ], + "name": "transferOwner", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "withdrawAll", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "withdrawAmount", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" } ] \ No newline at end of file diff --git a/Lock.sol b/Lock.sol index 443f7ea..85cc889 100644 --- a/Lock.sol +++ b/Lock.sol @@ -1,4 +1,5 @@ -pragma solidity >=0.7.0 <0.9.0; +// SPDX-License-Identifier: GPL-3.0 +pragma solidity ^0.8.0; contract Lock { //合约拥有者账号地址 @@ -9,20 +10,23 @@ contract Lock { bool _enabled = true; + uint durationOne = 15 days; + uint durationSec = 540 days; + //抵押状态 struct Record { //抵押额度(wei) uint value; - //单次提取时间(s) - uint64 slice; - //抵押起始时间(s) - uint64 startTime; - //总提取次数 - uint64 count; - //已提取次数 - uint64 freeCount; //用户索引 uint index; + //抵押起时间(s) + uint64 startTime; + //是否已释放首期抵押 + uint64 stageOne; + //已释放二期抵押份数 + uint64 stageSec; + //已释放抵押 + uint withdrawed; } struct QueryResult { @@ -30,32 +34,29 @@ contract Lock { uint lockedAmount; uint withdrawed; uint64 startTime; - uint64 slice; - uint64 count; } constructor() { owner = msg.sender; } - event USDTLog(address addr, uint amount, string txid); + event USDTLog(address indexed addr, uint amount, string txid); //直接抵押函数 - function lockLinear(address addr, uint64 timeSlice, uint64 count, string calldata txid) public payable { + function lock540(address addr, uint amount, string calldata txid) public payable { require(msg.value > 0, "value cannot be zero"); - require(address(msg.sender) == address(tx.origin), "no contract"); + require(msg.value >= amount, "illegal amount"); require(_enabled, "is disabled"); - require(count > 0 && count <= 36, "illegal count"); - require(timeSlice > 0 && timeSlice < 36500, "illegal time"); + require(address(msg.sender) == address(tx.origin), "no contract"); require(records[addr].value == 0, "lock exist"); records[addr] = Record({ value : msg.value, - slice : timeSlice * (1 days), + index : users.length, startTime : uint64(block.timestamp), - count : count, - freeCount : 0, - index : users.length + stageOne : 0, + stageSec : 0, + withdrawed : 0 }); users.push(addr); @@ -66,55 +67,46 @@ contract Lock { function querySelf() view public returns (uint, QueryResult memory result) { require(records[msg.sender].value > 0, "no record"); Record storage curRecord = records[msg.sender]; - uint share = curRecord.value / curRecord.count; result = QueryResult({ addr : msg.sender, lockedAmount : curRecord.value, - withdrawed : share * curRecord.freeCount, - startTime : curRecord.startTime, - slice : curRecord.slice, - count : curRecord.count + withdrawed : curRecord.withdrawed - balances[msg.sender], + startTime : curRecord.startTime }); return (block.timestamp, result); } //查询指定锁仓 - function queryAny(address addr) view public onlyOwner returns (QueryResult memory result) { + function queryAny(address addr) view public onlyOwner returns (uint, QueryResult memory result) { require(records[addr].value > 0, "no record"); Record storage curRecord = records[addr]; - uint share = curRecord.value / curRecord.count; result = QueryResult({ addr : addr, lockedAmount : curRecord.value, - withdrawed : share * curRecord.freeCount, - startTime : curRecord.startTime, - slice : curRecord.slice, - count : curRecord.count + withdrawed : curRecord.withdrawed - balances[addr], + startTime : curRecord.startTime }); - return result; + return (block.timestamp, result); } //查询全部锁仓 - function queryAll(uint start, uint size) view public onlyOwner returns (QueryResult[] memory) { + function queryAll(uint start, uint size) view public onlyOwner returns (uint, QueryResult[] memory) { require(start + size <= users.length, "overflow"); QueryResult[] memory result = new QueryResult[](size); uint end = start + size; for (uint i = start; i < end; i++) { Record storage curRecord = records[users[i]]; - uint share = curRecord.value / curRecord.count; result[i - start] = QueryResult({ addr : users[i], lockedAmount : curRecord.value, - withdrawed : share * curRecord.freeCount, - startTime : curRecord.startTime, - slice : curRecord.slice, - count : curRecord.count + withdrawed : curRecord.withdrawed - balances[users[i]], + startTime : curRecord.startTime }); } - return result; + return (block.timestamp, result); } function getAllCount() onlyOwner public view returns (uint count) { @@ -133,35 +125,56 @@ contract Lock { delete records[addr]; } - function settle_(address addr) private { + //结算锁仓,返回是否已结清 + function settle_(address addr) private returns (bool) { Record storage curRecord = records[addr]; - uint share = curRecord.value / curRecord.count; uint curTime = block.timestamp; + uint64 day = uint64((curTime / (1 days)) - (curRecord.startTime / (1 days))); //抵押已到期 - if (curTime >= curRecord.startTime + curRecord.slice * curRecord.count) { + if (day >= 555) {// 15+540 //剩余抵押 - uint amount = curRecord.value - share * curRecord.freeCount; - curRecord.freeCount = curRecord.count; + uint amount = curRecord.value - curRecord.withdrawed; + //已结清 + if (amount == 0) { + return true; + } + curRecord.stageOne = 1; + curRecord.stageSec = 540; + curRecord.withdrawed = curRecord.value; balances[addr] += amount; - deleteUser(addr); - return; + return true; + } + + if (day < 15) { + return false; + } + day -= 15; + + //释放第一阶段 + uint shareOne = curRecord.value * 5 / 100; + if (curRecord.stageOne == 0) { + curRecord.stageOne = 1; + curRecord.withdrawed += shareOne; + balances[addr] += shareOne; } - uint times = (curTime - uint(curRecord.startTime)) / curRecord.slice; - //按时间释放 - if (times > curRecord.freeCount) { - uint amount = (times - curRecord.freeCount) * share; - curRecord.freeCount = uint64(times); + //释放第二阶段 + uint shareSec = curRecord.value - shareOne; + if (day > curRecord.stageSec) { + uint amount = shareSec * (day - curRecord.stageSec) / 540; + curRecord.withdrawed += amount; + curRecord.stageSec = day; balances[addr] += amount; } + return false; } //提取指定余额 function withdrawAmount(uint amount) public { require(address(msg.sender) == address(tx.origin), "no contract"); - if (records[msg.sender].value > 0) { - settle_(msg.sender); + if (settle_(msg.sender) && amount == balances[msg.sender]) { + deleteUser(msg.sender); } require(balances[msg.sender] >= amount, "not enough"); @@ -172,8 +185,8 @@ contract Lock { //提取全部余额 function withdrawAll() public { require(address(msg.sender) == address(tx.origin), "no contract"); - if (records[msg.sender].value > 0) { - settle_(msg.sender); + if (settle_(msg.sender)) { + deleteUser(msg.sender); } uint amount = balances[msg.sender]; @@ -183,7 +196,7 @@ contract Lock { function transferLock(address addr) public { require(records[addr].value == 0, "lock exist"); - require(addr != msg.sender, "no self"); + require(addr != msg.sender && addr != address(0), "no self"); users.push(addr); records[addr] = records[msg.sender]; diff --git a/Readme.md b/Readme.md index 0c89ec3..627bbbd 100644 --- a/Readme.md +++ b/Readme.md @@ -1,3 +1,52 @@ ## ETD Lock Contract -address: 0x3d90df95377811A4E0574Dfe9069fD319FE5eB2D \ No newline at end of file +address: 0x4b5116c166e7E1682335fE50ACB9e7C01e34b14c +minutes version address: 0x2c8AAbD89dCc7aD8a8426011367680cAE267175B + +1. Lock_540(addr, amount, usdtTxid) + + 1. addr为锁仓收款地址 + 2. amount为锁定数量,要求msg.sender.value >= amount + 3. 释放规则(分为两个线性阶段): + 1. 从锁仓开始记为第⼀天,在第15天释放 amount * 5%;(⼀期) + 2. 从第16天开始,持续540天,每天释放amount*95%的1/540;(540期) + +2. withdrawAll() + + 提取msg.sender的当前可以提取的所有ETD + +3. withdrawAmount(amount)// refuse if amount > num_unlocked + + 提取msg.sender的当前可提取的amount数量ETD,若当前可提取数量不⾜amount,则失败 + +4. querySelf()// {now, addr, lockedAmount, withdrawed, startTime} + + 查询msg.sender的锁仓列表 + +5. queryAll _owner(start, size)// {now, []{addr, lockedAmount, withdrawed, startTime}} + + 查询所有的锁仓详情,owner权限 + +6. queryAny _owner(addr) // {now, addr, lockedAmount, withdrawed, startTime} + + 查询addr的锁仓详情,owner权限 + +7. getAllCount _owner() + + 当前锁仓总条数 + +8. transferLock(addr) + + 转移msg.sender的锁仓记录给addr + +9. transferOwner _owner(addr) + + 转移owner权限 + +10. getOwer() + + 返回owner地址 + +11. changeStatus _owner() + + 开启/关闭锁仓功能 \ No newline at end of file From f1bf9def431b97320e60930de924f368d0392b13 Mon Sep 17 00:00:00 2001 From: zpykillccc <79955764+zpykillccc@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:47:27 +0800 Subject: [PATCH 02/11] Update Lock.sol --- Lock.sol | 252 ++++++++++++++++++++++++------------------------------- 1 file changed, 110 insertions(+), 142 deletions(-) diff --git a/Lock.sol b/Lock.sol index 85cc889..d95fece 100644 --- a/Lock.sol +++ b/Lock.sol @@ -1,228 +1,196 @@ // SPDX-License-Identifier: GPL-3.0 -pragma solidity ^0.8.0; +pragma solidity >=0.7.0 <0.9.0; contract Lock { - //合约拥有者账号地址 address private owner; - mapping(address => Record) records; - mapping(address => uint) balances; + mapping (address => Record) records; + mapping (address => uint) balances; address[] users; - + bool _enabled = true; - + uint durationOne = 15 days; uint durationSec = 540 days; - + //抵押状态 struct Record { - //抵押额度(wei) + //抵押额度 wei uint value; - //用户索引 - uint index; - //抵押起时间(s) + //抵押起始时间 uint64 startTime; - //是否已释放首期抵押 + //总提取次数 + uint index; + //是否已经释放首期 uint64 stageOne; - //已释放二期抵押份数 + //二期抵押 uint64 stageSec; //已释放抵押 uint withdrawed; } - + struct QueryResult { address addr; uint lockedAmount; uint withdrawed; uint64 startTime; } - + constructor() { owner = msg.sender; } - + event USDTLog(address indexed addr, uint amount, string txid); - - //直接抵押函数 - function lock540(address addr, uint amount, string calldata txid) public payable { - require(msg.value > 0, "value cannot be zero"); - require(msg.value >= amount, "illegal amount"); - require(_enabled, "is disabled"); - require(address(msg.sender) == address(tx.origin), "no contract"); - require(records[addr].value == 0, "lock exist"); - + + function lock_540_once(address addr, uint amount, string calldata txidUSDT) public payable { + require(msg.value > 0,"value cannot be zero"); + require(address(msg.sender) == address(tx.origin),"no cantract"); + require(_enabled,"is disable"); + require(records[addr].value == 0,"lock exist"); + require(msg.value > amount); + records[addr] = Record({ - value : msg.value, - index : users.length, - startTime : uint64(block.timestamp), - stageOne : 0, - stageSec : 0, - withdrawed : 0 + value : msg.value, + index : users.length, + startTime : uint64(block.timestamp), + stageOne : 0, + stageSec : 0, + withdrawed : 0 }); - users.push(addr); - emit USDTLog(addr, msg.value, txid); + emit USDTLog(addr, msg.value, txidUSDT); } - - //查询自身锁仓 - function querySelf() view public returns (uint, QueryResult memory result) { - require(records[msg.sender].value > 0, "no record"); + + function querySelf() view public returns(uint, QueryResult memory result) { + require(records[msg.sender].value > 0,"no records"); Record storage curRecord = records[msg.sender]; - + result = QueryResult({ - addr : msg.sender, - lockedAmount : curRecord.value, - withdrawed : curRecord.withdrawed - balances[msg.sender], - startTime : curRecord.startTime + addr : msg.sender, + lockedAmount : curRecord.value, + withdrawed : curRecord.withdrawed - balances[msg.sender], + startTime : curRecord.startTime }); - return (block.timestamp, result); + return(block.timestamp, result); + } + + function queryAll(uint start, uint size) view public onlyOwner returns(uint, QueryResult[] memory) { + require(start + size <= users.length,"overflow"); + QueryResult[] memory result = new QueryResult[](size); + uint end =start + size; + for (uint i = start; i < end; i++){ + Record storage curRecord = records[users[i]]; + result[i-start] = QueryResult({ + addr : users[i], + lockedAmount : curRecord.value, + withdrawed : curRecord.withdrawed - balances[users[i]], + startTime : curRecord.startTime + }); + } + return (block.timestamp,result); } - - //查询指定锁仓 - function queryAny(address addr) view public onlyOwner returns (uint, QueryResult memory result) { + + function QueryAny(address addr) view public onlyOwner returns(uint, QueryResult memory result){ require(records[addr].value > 0, "no record"); Record storage curRecord = records[addr]; - result = QueryResult({ - addr : addr, - lockedAmount : curRecord.value, - withdrawed : curRecord.withdrawed - balances[addr], - startTime : curRecord.startTime + addr : addr, + lockedAmount : curRecord.value, + withdrawed : curRecord.withdrawed - balances[addr], + startTime : curRecord.startTime }); return (block.timestamp, result); } - - //查询全部锁仓 - function queryAll(uint start, uint size) view public onlyOwner returns (uint, QueryResult[] memory) { - require(start + size <= users.length, "overflow"); - QueryResult[] memory result = new QueryResult[](size); - - uint end = start + size; - for (uint i = start; i < end; i++) { - Record storage curRecord = records[users[i]]; - result[i - start] = QueryResult({ - addr : users[i], - lockedAmount : curRecord.value, - withdrawed : curRecord.withdrawed - balances[users[i]], - startTime : curRecord.startTime - }); - } - return (block.timestamp, result); - } - - function getAllCount() onlyOwner public view returns (uint count) { - return users.length; - } - + function deleteUser(address addr) private { - //删除用户 uint index = records[addr].index; uint end = users.length - 1; if (index < end) { users[index] = users[end]; - records[users[end]].index = index; + records[users[end]].index = index; } users.pop(); delete records[addr]; } - - //结算锁仓,返回是否已结清 - function settle_(address addr) private returns (bool) { + + function settle_(address addr) private returns(bool) { Record storage curRecord = records[addr]; uint curTime = block.timestamp; - - uint64 day = uint64((curTime / (1 days)) - (curRecord.startTime / (1 days))); - //抵押已到期 - if (day >= 555) {// 15+540 - //剩余抵押 + + uint64 day = uint64(((curTime) / (1 days)) - ((curRecord.startTime) / (1 days))); + if (day >= 555){ uint amount = curRecord.value - curRecord.withdrawed; - //已结清 - if (amount == 0) { + if (amount == 0){ return true; } curRecord.stageOne = 1; - curRecord.stageSec = 540; + curRecord.stageSec = 1; curRecord.withdrawed = curRecord.value; balances[addr] += amount; return true; } - - if (day < 15) { + + if (day < 15){ return false; } + day -= 15; - - //释放第一阶段 - uint shareOne = curRecord.value * 5 / 100; - if (curRecord.stageOne == 0) { - curRecord.stageOne = 1; - curRecord.withdrawed += shareOne; - balances[addr] += shareOne; - } - - //释放第二阶段 - uint shareSec = curRecord.value - shareOne; - if (day > curRecord.stageSec) { - uint amount = shareSec * (day - curRecord.stageSec) / 540; - curRecord.withdrawed += amount; - curRecord.stageSec = day; - balances[addr] += amount; + + uint shareOne = curRecord.value *5 / 100; + if (curRecord.stageOne == 0){ + curRecord.stageOne = 1; + curRecord.withdrawed += shareOne; + balances[addr] += shareOne; } + return false; + } - - //提取指定余额 - function withdrawAmount(uint amount) public { - require(address(msg.sender) == address(tx.origin), "no contract"); - if (settle_(msg.sender) && amount == balances[msg.sender]) { - deleteUser(msg.sender); - } - - require(balances[msg.sender] >= amount, "not enough"); - balances[msg.sender] -= amount; - payable(msg.sender).transfer(amount); - } - - //提取全部余额 - function withdrawAll() public { - require(address(msg.sender) == address(tx.origin), "no contract"); - if (settle_(msg.sender)) { + + function withdraAll() public { + require(address(msg.sender) == address(tx.origin),"no cantract"); + if (settle_(msg.sender)){ deleteUser(msg.sender); } - + uint amount = balances[msg.sender]; balances[msg.sender] = 0; payable(msg.sender).transfer(amount); } - + + + function getAllCount() view public onlyOwner returns(uint) { + return users.length; + } + function transferLock(address addr) public { - require(records[addr].value == 0, "lock exist"); - require(addr != msg.sender && addr != address(0), "no self"); - + require(records[addr].value ==0, "lock exist"); + require(addr != msg.sender && addr != address(0), "not self"); + users.push(addr); records[addr] = records[msg.sender]; deleteUser(msg.sender); } - - //设置开始状态 - function changeStatus(bool flag) public onlyOwner { - _enabled = flag; + + function transferOnwer(address paramOwner) public onlyOwner { + if (paramOwner != address(0)){ + owner = paramOwner; + } } - - function transferOwner(address paramOwner) public onlyOwner { - require(paramOwner != address(0)); - owner = paramOwner; + + function changeStatus(bool flag) public onlyOwner { + _enabled = flag; } - - modifier onlyOwner(){ - require(msg.sender == owner, "only owner"); + + modifier onlyOwner() { + require (msg.sender == owner,"only owner"); _; } - + function getOwner() public view returns (address) { return owner; } - - function isEnabled() public view returns (bool) { + + function isEnable() public view returns (bool) { return _enabled; } -} \ No newline at end of file +} From fb682e43da47fc21bb35cece22cb1d717c760ebc Mon Sep 17 00:00:00 2001 From: zpykillccc <79955764+zpykillccc@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:49:03 +0800 Subject: [PATCH 03/11] Update ABI.json --- ABI.json | 565 +++++++++++++++++++++++++++---------------------------- 1 file changed, 276 insertions(+), 289 deletions(-) diff --git a/ABI.json b/ABI.json index 80662e5..3fc1115 100644 --- a/ABI.json +++ b/ABI.json @@ -1,290 +1,277 @@ [ - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "addr", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "string", - "name": "txid", - "type": "string" - } - ], - "name": "USDTLog", - "type": "event" - }, - { - "inputs": [ - { - "internalType": "bool", - "name": "flag", - "type": "bool" - } - ], - "name": "changeStatus", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "getAllCount", - "outputs": [ - { - "internalType": "uint256", - "name": "count", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getOwner", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "isEnabled", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "addr", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "string", - "name": "txid", - "type": "string" - } - ], - "name": "lock540", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "start", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "size", - "type": "uint256" - } - ], - "name": "queryAll", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "address", - "name": "addr", - "type": "address" - }, - { - "internalType": "uint256", - "name": "lockedAmount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawed", - "type": "uint256" - }, - { - "internalType": "uint64", - "name": "startTime", - "type": "uint64" - } - ], - "internalType": "struct Lock.QueryResult[]", - "name": "", - "type": "tuple[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "addr", - "type": "address" - } - ], - "name": "queryAny", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "address", - "name": "addr", - "type": "address" - }, - { - "internalType": "uint256", - "name": "lockedAmount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawed", - "type": "uint256" - }, - { - "internalType": "uint64", - "name": "startTime", - "type": "uint64" - } - ], - "internalType": "struct Lock.QueryResult", - "name": "result", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "querySelf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "address", - "name": "addr", - "type": "address" - }, - { - "internalType": "uint256", - "name": "lockedAmount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawed", - "type": "uint256" - }, - { - "internalType": "uint64", - "name": "startTime", - "type": "uint64" - } - ], - "internalType": "struct Lock.QueryResult", - "name": "result", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "addr", - "type": "address" - } - ], - "name": "transferLock", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "paramOwner", - "type": "address" - } - ], - "name": "transferOwner", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "withdrawAll", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "withdrawAmount", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } -] \ No newline at end of file + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "addr", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "txid", + "type": "string" + } + ], + "name": "USDTLog", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "addr", + "type": "address" + } + ], + "name": "QueryAny", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "address", + "name": "addr", + "type": "address" + }, + { + "internalType": "uint256", + "name": "lockedAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawed", + "type": "uint256" + }, + { + "internalType": "uint64", + "name": "startTime", + "type": "uint64" + } + ], + "internalType": "struct Lock.QueryResult", + "name": "result", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bool", + "name": "flag", + "type": "bool" + } + ], + "name": "changeStatus", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getAllCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getOwner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "isEnable", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "addr", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "string", + "name": "txidUSDT", + "type": "string" + } + ], + "name": "lock_540_once", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "start", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "size", + "type": "uint256" + } + ], + "name": "queryAll", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "address", + "name": "addr", + "type": "address" + }, + { + "internalType": "uint256", + "name": "lockedAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawed", + "type": "uint256" + }, + { + "internalType": "uint64", + "name": "startTime", + "type": "uint64" + } + ], + "internalType": "struct Lock.QueryResult[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "querySelf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "address", + "name": "addr", + "type": "address" + }, + { + "internalType": "uint256", + "name": "lockedAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawed", + "type": "uint256" + }, + { + "internalType": "uint64", + "name": "startTime", + "type": "uint64" + } + ], + "internalType": "struct Lock.QueryResult", + "name": "result", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "addr", + "type": "address" + } + ], + "name": "transferLock", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "paramOwner", + "type": "address" + } + ], + "name": "transferOnwer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "withdraAll", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] From 6a34ebee49b737e863791be9cea737400c85ecc3 Mon Sep 17 00:00:00 2001 From: zpykillccc <79955764+zpykillccc@users.noreply.github.com> Date: Wed, 24 Nov 2021 20:04:47 +0800 Subject: [PATCH 04/11] Update Readme.md --- Readme.md | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/Readme.md b/Readme.md index 627bbbd..b6bf227 100644 --- a/Readme.md +++ b/Readme.md @@ -1,29 +1,26 @@ ## ETD Lock Contract -address: 0x4b5116c166e7E1682335fE50ACB9e7C01e34b14c -minutes version address: 0x2c8AAbD89dCc7aD8a8426011367680cAE267175B +address: 0xd13d1bbea9559230ce013fc5e4700e31339c4ed1 -1. Lock_540(addr, amount, usdtTxid) +1. Lock_540_once(addr, amount, usdtTxid) - 1. addr为锁仓收款地址 - 2. amount为锁定数量,要求msg.sender.value >= amount - 3. 释放规则(分为两个线性阶段): - 1. 从锁仓开始记为第⼀天,在第15天释放 amount * 5%;(⼀期) - 2. 从第16天开始,持续540天,每天释放amount*95%的1/540;(540期) + 1.addr 为锁仓收款地址 + 2.amount为锁定数量 + 3.txidUSDT可以为空 + 4.每⼀个addr持有的锁仓条⽬上限为1 + 5. 释放规则(分为两个线性阶段): + 1. 从锁仓开始记为第⼀天,第540天⼀次性释放 2. withdrawAll() - 提取msg.sender的当前可以提取的所有ETD + 提取msg.sender的当前可以提取的所有ETD(⼀次性释放,即为>=540天后,可提取全部,<540时可提取为0) -3. withdrawAmount(amount)// refuse if amount > num_unlocked - 提取msg.sender的当前可提取的amount数量ETD,若当前可提取数量不⾜amount,则失败 - -4. querySelf()// {now, addr, lockedAmount, withdrawed, startTime} +3. querySelf()// {now, addr, lockedAmount, withdrawed, startTime} 查询msg.sender的锁仓列表 -5. queryAll _owner(start, size)// {now, []{addr, lockedAmount, withdrawed, startTime}} +4. queryAll _owner(start, size)// {now, []{addr, lockedAmount, withdrawed, startTime}} 查询所有的锁仓详情,owner权限 @@ -49,4 +46,4 @@ minutes version address: 0x2c8AAbD89dCc7aD8a8426011367680cAE267175B 11. changeStatus _owner() - 开启/关闭锁仓功能 \ No newline at end of file + 开启/关闭锁仓功能 From 95100e3b1586f6c5184baf4b679b3b3557eca4b6 Mon Sep 17 00:00:00 2001 From: zpykillccc <79955764+zpykillccc@users.noreply.github.com> Date: Thu, 25 Nov 2021 10:29:09 +0800 Subject: [PATCH 05/11] Update Lock.sol --- Lock.sol | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/Lock.sol b/Lock.sol index d95fece..e7a461a 100644 --- a/Lock.sol +++ b/Lock.sol @@ -9,8 +9,7 @@ contract Lock { bool _enabled = true; - uint durationOne = 15 days; - uint durationSec = 540 days; + // uint durationSec = 540 days; //抵押状态 struct Record { @@ -21,9 +20,7 @@ contract Lock { //总提取次数 uint index; //是否已经释放首期 - uint64 stageOne; - //二期抵押 - uint64 stageSec; + uint64 stage; //已释放抵押 uint withdrawed; } @@ -52,8 +49,7 @@ contract Lock { value : msg.value, index : users.length, startTime : uint64(block.timestamp), - stageOne : 0, - stageSec : 0, + stage : 0, withdrawed : 0 }); users.push(addr); @@ -117,31 +113,17 @@ contract Lock { uint curTime = block.timestamp; uint64 day = uint64(((curTime) / (1 days)) - ((curRecord.startTime) / (1 days))); - if (day >= 555){ + if (day >= 540){ uint amount = curRecord.value - curRecord.withdrawed; if (amount == 0){ return true; } - curRecord.stageOne = 1; - curRecord.stageSec = 1; + curRecord.stage = 1; curRecord.withdrawed = curRecord.value; balances[addr] += amount; return true; } - - if (day < 15){ - return false; - } - - day -= 15; - - uint shareOne = curRecord.value *5 / 100; - if (curRecord.stageOne == 0){ - curRecord.stageOne = 1; - curRecord.withdrawed += shareOne; - balances[addr] += shareOne; - } - + return false; } From b4fda50cc420ef360dfcdd8161dd91b81deb5bd9 Mon Sep 17 00:00:00 2001 From: zpykillccc <79955764+zpykillccc@users.noreply.github.com> Date: Thu, 25 Nov 2021 10:30:41 +0800 Subject: [PATCH 06/11] Update ABI.json From a67a7992db8e48daa4c2aed43ead81cd2a629118 Mon Sep 17 00:00:00 2001 From: zpykillccc <79955764+zpykillccc@users.noreply.github.com> Date: Thu, 25 Nov 2021 21:48:48 +0800 Subject: [PATCH 07/11] Update Lock.sol --- Lock.sol | 50 +++++++++++--------------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/Lock.sol b/Lock.sol index e7a461a..2d340ab 100644 --- a/Lock.sol +++ b/Lock.sol @@ -4,13 +4,10 @@ pragma solidity >=0.7.0 <0.9.0; contract Lock { address private owner; mapping (address => Record) records; - mapping (address => uint) balances; address[] users; bool _enabled = true; - // uint durationSec = 540 days; - //抵押状态 struct Record { //抵押额度 wei @@ -19,17 +16,13 @@ contract Lock { uint64 startTime; //总提取次数 uint index; - //是否已经释放首期 - uint64 stage; - //已释放抵押 - uint withdrawed; } struct QueryResult { address addr; uint lockedAmount; - uint withdrawed; uint64 startTime; + uint withdrawed; } constructor() { @@ -47,10 +40,8 @@ contract Lock { records[addr] = Record({ value : msg.value, - index : users.length, startTime : uint64(block.timestamp), - stage : 0, - withdrawed : 0 + index : users.length }); users.push(addr); emit USDTLog(addr, msg.value, txidUSDT); @@ -63,7 +54,7 @@ contract Lock { result = QueryResult({ addr : msg.sender, lockedAmount : curRecord.value, - withdrawed : curRecord.withdrawed - balances[msg.sender], + withdrawed : 0, startTime : curRecord.startTime }); return(block.timestamp, result); @@ -78,7 +69,7 @@ contract Lock { result[i-start] = QueryResult({ addr : users[i], lockedAmount : curRecord.value, - withdrawed : curRecord.withdrawed - balances[users[i]], + withdrawed : 0, startTime : curRecord.startTime }); } @@ -91,7 +82,7 @@ contract Lock { result = QueryResult({ addr : addr, lockedAmount : curRecord.value, - withdrawed : curRecord.withdrawed - balances[addr], + withdrawed : 0, startTime : curRecord.startTime }); return (block.timestamp, result); @@ -108,35 +99,16 @@ contract Lock { delete records[addr]; } - function settle_(address addr) private returns(bool) { - Record storage curRecord = records[addr]; - uint curTime = block.timestamp; - - uint64 day = uint64(((curTime) / (1 days)) - ((curRecord.startTime) / (1 days))); - if (day >= 540){ - uint amount = curRecord.value - curRecord.withdrawed; - if (amount == 0){ - return true; - } - curRecord.stage = 1; - curRecord.withdrawed = curRecord.value; - balances[addr] += amount; - return true; - } - - return false; - - } function withdraAll() public { require(address(msg.sender) == address(tx.origin),"no cantract"); - if (settle_(msg.sender)){ + Record storage curRecord = records[msg.sender]; + uint curTime = block.timestamp; + uint64 day = uint64(((curTime) / (1 days)) - ((curRecord.startTime) / (1 days))); + if (day > 540){ deleteUser(msg.sender); - } - - uint amount = balances[msg.sender]; - balances[msg.sender] = 0; - payable(msg.sender).transfer(amount); + payable(msg.sender).transfer(curRecord.value); + } } From afe69507d3a12ee3246bb1358ba25794d6e6cfcd Mon Sep 17 00:00:00 2001 From: zpykillccc <79955764+zpykillccc@users.noreply.github.com> Date: Thu, 25 Nov 2021 21:49:31 +0800 Subject: [PATCH 08/11] Update ABI.json --- ABI.json | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ABI.json b/ABI.json index 3fc1115..e95837e 100644 --- a/ABI.json +++ b/ABI.json @@ -56,15 +56,15 @@ "name": "lockedAmount", "type": "uint256" }, - { - "internalType": "uint256", - "name": "withdrawed", - "type": "uint256" - }, { "internalType": "uint64", "name": "startTime", "type": "uint64" + }, + { + "internalType": "uint256", + "name": "withdrawed", + "type": "uint256" } ], "internalType": "struct Lock.QueryResult", @@ -182,15 +182,15 @@ "name": "lockedAmount", "type": "uint256" }, - { - "internalType": "uint256", - "name": "withdrawed", - "type": "uint256" - }, { "internalType": "uint64", "name": "startTime", "type": "uint64" + }, + { + "internalType": "uint256", + "name": "withdrawed", + "type": "uint256" } ], "internalType": "struct Lock.QueryResult[]", @@ -222,15 +222,15 @@ "name": "lockedAmount", "type": "uint256" }, - { - "internalType": "uint256", - "name": "withdrawed", - "type": "uint256" - }, { "internalType": "uint64", "name": "startTime", "type": "uint64" + }, + { + "internalType": "uint256", + "name": "withdrawed", + "type": "uint256" } ], "internalType": "struct Lock.QueryResult", From 2fb95c0b0d3dfd91444beeb0fc05fe1af023c0f0 Mon Sep 17 00:00:00 2001 From: zpykillccc <79955764+zpykillccc@users.noreply.github.com> Date: Thu, 25 Nov 2021 21:54:34 +0800 Subject: [PATCH 09/11] Update Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index b6bf227..9ced50a 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,6 @@ ## ETD Lock Contract -address: 0xd13d1bbea9559230ce013fc5e4700e31339c4ed1 +address: 0x9619b85f71fe7f1f805d1a41b39a37933d9d3b29 1. Lock_540_once(addr, amount, usdtTxid) From a267b7239250f6bd0d3d62009e4c23b3c59c49b4 Mon Sep 17 00:00:00 2001 From: zpykillccc <79955764+zpykillccc@users.noreply.github.com> Date: Wed, 8 Dec 2021 16:14:55 +0800 Subject: [PATCH 10/11] Update Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 9ced50a..f03f6c5 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,6 @@ ## ETD Lock Contract -address: 0x9619b85f71fe7f1f805d1a41b39a37933d9d3b29 +address: 0x7b7c74c2d0f4b7222ede26cae13a4e85a3b69e90 1. Lock_540_once(addr, amount, usdtTxid) From c4c729e22123e29972f08a1595e7372658fbd467 Mon Sep 17 00:00:00 2001 From: zpykillccc <79955764+zpykillccc@users.noreply.github.com> Date: Wed, 8 Dec 2021 16:17:13 +0800 Subject: [PATCH 11/11] Update Lock.sol --- Lock.sol | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lock.sol b/Lock.sol index 2d340ab..97da43e 100644 --- a/Lock.sol +++ b/Lock.sol @@ -30,13 +30,14 @@ contract Lock { } event USDTLog(address indexed addr, uint amount, string txid); - + + function lock_540_once(address addr, uint amount, string calldata txidUSDT) public payable { require(msg.value > 0,"value cannot be zero"); require(address(msg.sender) == address(tx.origin),"no cantract"); require(_enabled,"is disable"); require(records[addr].value == 0,"lock exist"); - require(msg.value > amount); + require(msg.value >= amount,"amount false"); records[addr] = Record({ value : msg.value,