From 72c31a109894eac9c8d357302240a989ce725978 Mon Sep 17 00:00:00 2001 From: Sebastian Kim Date: Fri, 6 Nov 2020 16:43:05 +0900 Subject: [PATCH] Add more variables on token stats --- README.md | 52 +++++++++++++++++++--------------------- contracts/LockUpPool.sol | 29 ++++++++++++++++------ 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 9d884f8..452aa20 100644 --- a/README.md +++ b/README.md @@ -32,60 +32,58 @@ A governance token distribution contract on top of LockUpPool. A maximum of 1.2M ## Gas consumption ``` ·------------------------------------------|----------------------------|-------------|----------------------------· -| Solc version: 0.6.12+commit.27d51765 · Optimizer enabled: false · Runs: 200 · Block limit: 6718946 gas │ +| Solc version: 0.7.1+commit.f4a555be · Optimizer enabled: false · Runs: 200 · Block limit: 6718946 gas │ ···········································|····························|·············|····························· -| Methods · 15 gwei/gas · 394.76 usd/eth │ +| Methods · 38 gwei/gas · 433.90 usd/eth │ ··················|························|··············|·············|·············|··············|·············· | Contract · Method · Min · Max · Avg · # calls · usd (avg) │ ··················|························|··············|·············|·············|··············|·············· -| ERC20Token · addMinter · - · - · 73028 · 23 · 0.43 │ +| ERC20Token · addMinter · 73038 · 73050 · 73048 · 23 · 1.20 │ ··················|························|··············|·············|·············|··············|·············· -| ERC20Token · approve · 29166 · 44274 · 43984 · 122 · 0.26 │ +| ERC20Token · approve · 29166 · 44274 · 43976 · 120 · 0.73 │ ··················|························|··············|·············|·············|··············|·············· -| ERC20Token · initialize · 332847 · 371415 · 361514 · 90 · 2.14 │ +| ERC20Token · initialize · 328285 · 373313 · 361760 · 90 · 5.96 │ ··················|························|··············|·············|·············|··············|·············· -| ERC20Token · mint · - · - · 53163 · 49 · 0.31 │ +| ERC20Token · mint · - · - · 53096 · 49 · 0.88 │ ··················|························|··············|·············|·············|··············|·············· -| ERC20Token · transfer · 52261 · 52321 · 52318 · 22 · 0.31 │ +| ERC20Token · transfer · 37283 · 52343 · 51623 · 21 · 0.85 │ ··················|························|··············|·············|·············|··············|·············· -| LockUpPool · addLockUpPool · 71511 · 86559 · 84934 · 37 · 0.50 │ +| LockUpPool · addLockUpPool · 71475 · 86559 · 84932 · 37 · 1.40 │ ··················|························|··············|·············|·············|··············|·············· -| LockUpPool · claimBonus · 26871 · 126643 · 73390 · 3 · 0.43 │ +| LockUpPool · claimBonus · 26883 · 126955 · 73598 · 3 · 1.21 │ ··················|························|··············|·············|·············|··············|·············· -| LockUpPool · doLockUp · 173460 · 293401 · 259079 · 46 · 1.53 │ +| LockUpPool · doLockUp · 193432 · 358373 · 301556 · 46 · 4.97 │ ··················|························|··············|·············|·············|··············|·············· -| LockUpPool · exit · 60474 · 205524 · 136703 · 31 · 0.81 │ +| LockUpPool · exit · 75503 · 273991 · 188522 · 31 · 3.11 │ ··················|························|··············|·············|·············|··············|·············· -| LockUpPool · initialize · - · - · 117219 · 31 · 0.69 │ +| LockUpPool · initialize · - · - · 137233 · 31 · 2.26 │ ··················|························|··············|·············|·············|··············|·············· -| LockUpPool · setEmergencyMode · - · - · 43232 · 4 · 0.26 │ +| LockUpPool · setEmergencyMode · - · - · 43232 · 4 · 0.71 │ ··················|························|··············|·············|·············|··············|·············· -| LockUpPool · updateMaxLimit · 28907 · 28979 · 28943 · 2 · 0.17 │ +| LockUpPool · updateMaxLimit · 28907 · 28967 · 28937 · 2 · 0.48 │ ··················|························|··············|·············|·············|··············|·············· -| Migrations · setCompleted · - · - · 27335 · 3 · 0.16 │ +| Migrations · setCompleted · - · - · 27335 · 3 · 0.45 │ ··················|························|··············|·············|·············|··············|·············· -| WRNRewardPool · addLockUpRewardPool · 100447 · 222790 · 133815 · 30 · 0.79 │ +| WRNRewardPool · addLockUpRewardPool · 100725 · 224037 · 133956 · 30 · 2.21 │ ··················|························|··············|·············|·············|··············|·············· -| WRNRewardPool · claimWRN · 146308 · 202108 · 183508 · 6 · 1.09 │ +| WRNRewardPool · claimWRN · 147577 · 203377 · 184777 · 6 · 3.05 │ ··················|························|··············|·············|·············|··············|·············· -| WRNRewardPool · doLockUp · 291836 · 395198 · 342116 · 24 · 2.03 │ +| WRNRewardPool · doLockUp · 327636 · 416140 · 393060 · 24 · 6.48 │ ··················|························|··············|·············|·············|··············|·············· -| WRNRewardPool · exit · 157230 · 288567 · 243177 · 7 · 1.44 │ +| WRNRewardPool · exit · 196963 · 358300 · 297910 · 7 · 4.91 │ ··················|························|··············|·············|·············|··············|·············· -| WRNRewardPool · initialize · - · - · 263264 · 23 · 1.56 │ +| WRNRewardPool · initialize · 283266 · 283278 · 283277 · 23 · 4.67 │ ··················|························|··············|·············|·············|··············|·············· -| WRNRewardPool · setEmergencyMode · - · - · 43277 · 1 · 0.26 │ +| WRNRewardPool · setEmergencyMode · - · - · 43277 · 1 · 0.71 │ ··················|························|··············|·············|·············|··············|·············· -| WRNRewardPool · updatePoolMultiplier · - · - · 221400 · 1 · 1.31 │ +| WRNRewardPool · updatePoolMultiplier · - · - · 223338 · 1 · 3.68 │ ··················|························|··············|·············|·············|··············|·············· | Deployments · · % of limit · │ ···········································|··············|·············|·············|··············|·············· -| ERC20Token · - · - · 3008792 · 44.8 % · 17.82 │ +| ERC20Token · - · - · 3022475 · 45 % · 49.84 │ ···········································|··············|·············|·············|··············|·············· -| LockUpPool · - · - · 2983744 · 44.4 % · 17.67 │ +| LockUpPool · - · - · 3052026 · 45.4 % · 50.32 │ ···········································|··············|·············|·············|··············|·············· -| Migrations · - · - · 186963 · 2.8 % · 1.11 │ -···········································|··············|·············|·············|··············|·············· -| WRNRewardPool · - · - · 4394387 · 65.4 % · 26.02 │ +| WRNRewardPool · - · - · 4470476 · 66.5 % · 73.71 │ ·------------------------------------------|--------------|-------------|-------------|--------------|-------------· ``` diff --git a/contracts/LockUpPool.sol b/contracts/LockUpPool.sol index 5968b19..c353fc1 100644 --- a/contracts/LockUpPool.sol +++ b/contracts/LockUpPool.sol @@ -34,18 +34,23 @@ contract LockUpPool is Initializable, OwnableUpgradeSafe { uint256 effectiveTotal; uint256 bonusClaimed; // only used for tracking uint256 bonusDebt; - uint256 lockedUpCount; + uint256 lockedUpCount; // accumulative lock-up count LockUp[] lockUps; } struct TokenStats { uint256 maxLockUpLimit; - uint256 totalLockUp; + uint256 totalLockUp; // info uint256 effectiveTotalLockUp; // sum(amount * durationBoost) - uint256 totalPenalty; - uint256 totalPlatformFee; - uint256 totalClaimed; + uint256 totalPenalty; // info + uint256 totalPlatformFee; // info + uint256 totalClaimed; // info uint256 accBonusPerShare; // Others' Penalty = My Bonus + uint256 accTotalLockUp; // info + uint256 accLockUpCount; // info + uint256 activeLockUpCount; // info + uint256 unlockedCount; // info + uint256 brokenCount; // info } // Token => TokenStats @@ -58,7 +63,7 @@ contract LockUpPool is Initializable, OwnableUpgradeSafe { mapping (address => mapping (address => UserLockUp)) public userLockUps; event LockedUp(address indexed token, address indexed account, uint256 amount, uint256 totalLockUp, uint256 durationInMonths, uint256 timestamp); - event Exited(address indexed token, address indexed account, uint256 amount, uint256 refundAmount, uint256 penalty, uint256 fee, uint256 remainingTotal, uint256 timestamp); + event Exited(address indexed token, address indexed account, uint256 amount, uint256 refundAmount, uint256 penalty, uint256 fee, uint256 remainingTotal, uint256 durationInMonths, uint256 timestamp); event BonusClaimed(address indexed token, address indexed account, uint256 amount, uint256 timestamp); // Fancy math here: @@ -168,6 +173,9 @@ contract LockUpPool is Initializable, OwnableUpgradeSafe { // Update TokenStats tokenStat.totalLockUp = tokenStat.totalLockUp.add(amount); + tokenStat.accTotalLockUp = tokenStat.accTotalLockUp.add(amount); + tokenStat.accLockUpCount = tokenStat.accLockUpCount.add(1); + tokenStat.activeLockUpCount = tokenStat.activeLockUpCount.add(1); tokenStat.effectiveTotalLockUp = tokenStat.effectiveTotalLockUp.add(effectiveAmount); _updateBonusDebt(tokenAddress, msg.sender); @@ -217,6 +225,13 @@ contract LockUpPool is Initializable, OwnableUpgradeSafe { tokenStat.totalPenalty = tokenStat.totalPenalty.add(penalty); tokenStat.totalPlatformFee = tokenStat.totalPlatformFee.add(fee); + tokenStat.activeLockUpCount = tokenStat.activeLockUpCount.sub(1); + if (penalty > 0) { + tokenStat.brokenCount = tokenStat.brokenCount.add(1); + } else { + tokenStat.unlockedCount = tokenStat.unlockedCount.add(1); + } + // Update user lockUp stats userLockUp.total = userLockUp.total.sub(lockUp.amount); userLockUp.effectiveTotal = userLockUp.effectiveTotal.sub(lockUp.effectiveAmount); @@ -234,7 +249,7 @@ contract LockUpPool is Initializable, OwnableUpgradeSafe { token.safeTransfer(msg.sender, refundAmount); token.safeTransfer(owner(), fee); // Platform fee - emit Exited(tokenAddress, msg.sender, lockUp.amount, refundAmount, penalty, fee, userLockUp.total, block.timestamp); + emit Exited(tokenAddress, msg.sender, lockUp.amount, refundAmount, penalty, fee, userLockUp.total, lockUp.durationInMonths, block.timestamp); } function earnedBonus(address tokenAddress) public view returns (uint256) {