Skip to content

Commit

Permalink
remove SafeMath
Browse files Browse the repository at this point in the history
  • Loading branch information
ququzone committed Mar 7, 2024
1 parent 5fa7386 commit 0e62a24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
19 changes: 8 additions & 11 deletions contracts/VestingMaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

contract VestingMaster is ReentrancyGuard, Ownable {
using SafeMath for uint256;
using EnumerableSet for EnumerableSet.AddressSet;

struct LockedReward {
Expand Down Expand Up @@ -43,7 +40,7 @@ contract VestingMaster is ReentrancyGuard, Ownable {
for (uint256 i = 0; i < oldLockedRewards.length; i++) {
lockedReward = oldLockedRewards[i];
if (lockedReward.locked > 0 && currentTimestamp >= lockedReward.timestamp) {
claimableAmount = claimableAmount.add(lockedReward.locked);
claimableAmount += lockedReward.locked;
delete oldLockedRewards[i];
}
}
Expand All @@ -57,19 +54,19 @@ contract VestingMaster is ReentrancyGuard, Ownable {
userLockedRewards[account].push(LockedReward({locked: claimableAmount, timestamp: newStartTimestamp}));
}
for (uint256 i = 0; i < lockedPeriodAmount; i++) {
newTimestamp = newStartTimestamp.add((i + 1) * period);
newTimestamp = newStartTimestamp + (i + 1) * period;
newLockedReward = LockedReward({locked: amount / lockedPeriodAmount, timestamp: newTimestamp});
for (uint256 j = jj; j < oldLockedRewards.length; j++) {
lockedReward = oldLockedRewards[j];
if (lockedReward.timestamp == newTimestamp) {
newLockedReward.locked = newLockedReward.locked.add(lockedReward.locked);
newLockedReward.locked += lockedReward.locked;
jj = j + 1;
break;
}
}
userLockedRewards[account].push(newLockedReward);
}
totalLockedRewards = totalLockedRewards.add(amount);
totalLockedRewards += amount;
emit Lock(account, amount);
return true;
}
Expand All @@ -82,11 +79,11 @@ contract VestingMaster is ReentrancyGuard, Ownable {
for (uint256 i = 0; i < lockedRewards.length; i++) {
lockedReward = lockedRewards[i];
if (lockedReward.locked > 0 && currentTimestamp > lockedReward.timestamp) {
claimableAmount = claimableAmount.add(lockedReward.locked);
claimableAmount += lockedReward.locked;
delete lockedRewards[i];
}
}
totalLockedRewards = totalLockedRewards.sub(claimableAmount);
totalLockedRewards == claimableAmount;
payable(msg.sender).transfer(claimableAmount);
emit Claim(msg.sender, claimableAmount);
return true;
Expand All @@ -99,9 +96,9 @@ contract VestingMaster is ReentrancyGuard, Ownable {
for (uint256 i = 0; i < lockedRewards.length; i++) {
lockedReward = lockedRewards[i];
if (currentTimestamp > lockedReward.timestamp) {
claimableAmount = claimableAmount.add(lockedReward.locked);
claimableAmount += lockedReward.locked;
} else {
lockedAmount = lockedAmount.add(lockedReward.locked);
lockedAmount += lockedReward.locked;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/factories/contracts/VestingMaster__factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ const _abi = [
] as const;

const _bytecode =
"0x60c03461015b57601f610fe238819003918201601f19168301916001600160401b0383118484101761016057808492604094855283398101031261015b57602081519101519060016000556001543360018060a01b031982161760015560405190339060018060a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3811561011b575081156100d15760805260a052604051610e4b908161017782396080518181816101d00152610579015260a0518181816102380152610a660152f35b60405162461bcd60e51b815260206004820152602e6024820152600080516020610fc283398151915260448201526d6f6420616d6f756e74207a65726f60901b6064820152608490fd5b62461bcd60e51b81526020600482015260276024820152600080516020610fc28339815191526044820152666f64207a65726f60c81b6064820152608490fd5b600080fd5b634e487b7160e01b600052604160045260246000fdfe6080604081815260048036101561001557600080fd5b600092833560e01c90816305e97bc614610a4f575080630b1bd24314610a055780630f950ea6146109e857806329da27f21461098b57806345cc5890146109195780634e71d92d146107ca57806363a44f12146107ab578063715018a61461074e5780638da5cb5b14610725578063a3fe795014610611578063ce62cd4a146105a0578063ef78d4fd14610561578063f2fde38b146104985763f435f5a7146100bd57600080fd5b60209283600319360112610495576100d3610a89565b6100db610c66565b3382526005855283822054156104425760018060a01b03169081815260029384865280822092835467ffffffffffffffff811161042f57610120888260051b01610b64565b81815294845287842084908987015b898b858510610415579350505050849150610148610b2e565b82815201528294835b85518110156101c7576101648187610bc8565b518051908a82151591826101b9575b5050610189575b5061018490610ba3565b610151565b610197906101849298610c59565b966101a0610b2e565b868152868b8201526101b28289610bc8565b529061017a565b015142101590508a38610173565b509091938688967f000000000000000000000000000000000000000000000000000000000000000091610203836101fe8142610bdc565b610bfc565b92878a61020e610b2e565b82815201528792878952828b528989208054908a8155816103d7575b5050806103af575b508793927f0000000000000000000000000000000000000000000000000000000000000000915b8286106102a5578b8b60018c8c61027234600354610c59565b6003557f625fed9875dada8643f2418b838ae0bc78d9a148a18eee4ee1979ff0f3f5d427858551348152a2555160018152f35b6001869a979b989c9599949601808b1161039c576102c6826102cc92610bfc565b8a610c59565b926102d78134610bdc565b996102e0610b2e565b9a8b5284878c0152835b8d5181101561037e576102fd818f610bc8565b51868982015114610317575061031290610ba3565b6102ea565b9092969b809499989f9b9e9a9d955061033592965051905190610c59565b82526001810180911161036b57949392916103629161035d90868f8d8f5b52528d8d20610c0f565b610ba3565b94939093610259565b634e487b7160e01b8b526011895260248bfd5b5092959c989b979a90935061035d859a888f610362959a988f610353565b634e487b7160e01b885260118d52602488fd5b6103d190888a52838c528a8a206103c4610b2e565b918252868d830152610c0f565b8a610232565b6001600160ff1b038216820361036b578a528b8a209084600191821b8301925b83811061040557505061022a565b8c81558c838201550185906103f7565b60019261042185610b8a565b81520192019201919061012f565b634e487b7160e01b845260418652602484fd5b835162461bcd60e51b8152808401869052602760248201527f56657374696e674d61737465723a2063616c6c6572206973206e6f7420746865604482015266103637b1b5b2b960c91b6064820152608490fd5b80fd5b503461055d57602036600319011261055d576104b2610a89565b906104bb610ad6565b6001600160a01b0391821692831561050b575050600180546001600160a01b031981168417909155167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b906020608492519162461bcd60e51b8352820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152fd5b8280fd5b50503461059c578160031936011261059c57602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b5080fd5b50503461059c57602036600319011261059c576105bb610a89565b6105c3610ad6565b6001600160a01b03168083526005602052908220546105e0575080f35b6105e981610d54565b507f95266445d018e5b30f957c915e91b04bb4a19bf0f8f21020a08dad9be7931df48280a280f35b50913461049557602090816003193601126104955761062e610a89565b6001600160a01b03168152600280835283822080549095839283929167ffffffffffffffff83116107125750610668868360051b01610b64565b828152978352858320839087808b015b8584106106f457509250505082915061068f610b2e565b8281520152915b85518310156106e7576106a98387610bc8565b51848101514211156106d0576106ca916106c4915190610c59565b92610ba3565b91610696565b6106ca9193926106e1915190610c59565b91610ba3565b9150918351928352820152f35b600191859161070285610b8a565b8152019201920191908890610678565b634e487b7160e01b845260419052602483fd5b50503461059c578160031936011261059c5760015490516001600160a01b039091168152602090f35b8334610495578060031936011261049557610767610ad6565b600180546001600160a01b0319811690915581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b50503461059c578160031936011261059c576020906003549051908152f35b5091346104955780600319360112610495576107e4610c66565b3381526020600281528282209082816107fb610b2e565b828152015282835b835481101561088c5761081f6108198286610aa4565b50610b8a565b80519084821515918261087f575b5050610843575b5061083e90610ba3565b610803565b61084d9192610c59565b906108588185610aa4565b61086d5785815560010185905561083e610834565b634e487b7160e01b8652858852602486fd5b015142119050843861082d565b5091509360035490828203918211610906575060035581808280156108fc575b8280929181923390f1156108f0579060019183519081527f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d4853392a2555160018152f35b509051903d90823e3d90fd5b6108fc91506108ac565b634e487b7160e01b845260119052602483fd5b50503461059c57602036600319011261059c57610934610a89565b61093c610ad6565b6001600160a01b03168083526005602052908220541561095a575080f35b61096381610cd7565b507f7c5af8d36d8be103bc583da8e01d3e98f15216cc7ef38832c7550b34e8feb43a8280a280f35b50503461059c578060031936011261059c576109a5610a89565b6001600160a01b031682526002602052808220805460243591908210156109e457906109d091610aa4565b506001815491015482519182526020820152f35b8380fd5b503461055d578260031936011261055d5760209250549051908152f35b5091346104955760203660031901126104955782358354811015610a3c5760209382528360018060a01b0392200154169051908152f35b634e487b7160e01b825260328452602482fd5b84903461059c578160031936011261059c576020907f00000000000000000000000000000000000000000000000000000000000000008152f35b600435906001600160a01b0382168203610a9f57565b600080fd5b8054821015610ac05760005260206000209060011b0190600090565b634e487b7160e01b600052603260045260246000fd5b6001546001600160a01b03163303610aea57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b604051906040820182811067ffffffffffffffff821117610b4e57604052565b634e487b7160e01b600052604160045260246000fd5b6040519190601f01601f1916820167ffffffffffffffff811183821017610b4e57604052565b906001610b95610b2e565b928054845201546020830152565b6000198114610bb25760010190565b634e487b7160e01b600052601160045260246000fd5b8051821015610ac05760209160051b010190565b8115610be6570490565b634e487b7160e01b600052601260045260246000fd5b81810292918115918404141715610bb257565b8054600160401b811015610b4e57610c2c91600182018155610aa4565b919091610c43576020816001925184550151910155565b634e487b7160e01b600052600060045260246000fd5b91908201809211610bb257565b600260005414610c77576002600055565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b600454811015610ac057600460005260206000200190600090565b600081815260056020526040812054610d4f57600454600160401b811015610d3b579082610d27610d1084600160409601600455610cbc565b819391549060031b91821b91600019901b19161790565b905560045492815260056020522055600190565b634e487b7160e01b82526041600452602482fd5b905090565b6000818152600560205260408120549091908015610e395760001990808201818111610e255760045490838201918211610e1157808203610ddd575b5050506004548015610dc957810190610da882610cbc565b909182549160031b1b19169055600455815260056020526040812055600190565b634e487b7160e01b84526031600452602484fd5b610dfb610dec610d1093610cbc565b90549060031b1c928392610cbc565b9055845260056020526040842055388080610d90565b634e487b7160e01b86526011600452602486fd5b634e487b7160e01b85526011600452602485fd5b50509056fea164736f6c6343000813000a56657374696e674d61737465723a3a636f6e7374727563746f723a2050657269";
"0x60c03461015b57601f610fbb38819003918201601f19168301916001600160401b0383118484101761016057808492604094855283398101031261015b57602081519101519060016000556001543360018060a01b031982161760015560405190339060018060a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3811561011b575081156100d15760805260a052604051610e24908161017782396080518181816101d00152610577015260a0518181816102380152610a3f0152f35b60405162461bcd60e51b815260206004820152602e6024820152600080516020610f9b83398151915260448201526d6f6420616d6f756e74207a65726f60901b6064820152608490fd5b62461bcd60e51b81526020600482015260276024820152600080516020610f9b8339815191526044820152666f64207a65726f60c81b6064820152608490fd5b600080fd5b634e487b7160e01b600052604160045260246000fdfe6080604081815260048036101561001557600080fd5b600092833560e01c90816305e97bc614610a28575080630b1bd243146109de5780630f950ea6146109c157806329da27f21461096457806345cc5890146108f25780634e71d92d146107c857806363a44f12146107a9578063715018a61461074c5780638da5cb5b14610723578063a3fe79501461060f578063ce62cd4a1461059e578063ef78d4fd1461055f578063f2fde38b146104965763f435f5a7146100bd57600080fd5b60209283600319360112610493576100d3610a62565b6100db610c3f565b3382526005855283822054156104405760018060a01b03169081815260029384865280822092835467ffffffffffffffff811161042d57610120888260051b01610b3d565b81815294845287842084908987015b898b858510610413579350505050849150610148610b07565b82815201528294835b85518110156101c7576101648187610ba1565b518051908a82151591826101b9575b5050610189575b5061018490610b7c565b610151565b610197906101849298610bb5565b966101a0610b07565b868152868b8201526101b28289610ba1565b529061017a565b015142101590508a38610173565b509091938688967f000000000000000000000000000000000000000000000000000000000000000091610203836101fe8142610bc2565b610be2565b92878a61020e610b07565b82815201528792878952828b528989208054908a8155816103d5575b5050806103ad575b508793927f0000000000000000000000000000000000000000000000000000000000000000915b8286106102a5578b8b60018c8c61027234600354610bb5565b6003557f625fed9875dada8643f2418b838ae0bc78d9a148a18eee4ee1979ff0f3f5d427858551348152a2555160018152f35b6001869a979b989c9599949601808b1161039a576102c6826102cc92610be2565b8a610bb5565b926102d78134610bc2565b996102e0610b07565b9a8b5284878c0152835b8d5181101561037c576102fd818f610ba1565b51868982015114610317575061031290610b7c565b6102ea565b9092969b9398979e9a9d999c9450610333919550518351610bb5565b82526001810180911161036957949392916103609161035b90868f8d8f5b52528d8d20610bf5565b610b7c565b94939093610259565b634e487b7160e01b8b526011895260248bfd5b5092959c989b979a90935061035b859a888f610360959a988f610351565b634e487b7160e01b885260118d52602488fd5b6103cf90888a52838c528a8a206103c2610b07565b918252868d830152610bf5565b8a610232565b6001600160ff1b0382168203610369578a528b8a209084600191821b8301925b83811061040357505061022a565b8c81558c838201550185906103f5565b60019261041f85610b63565b81520192019201919061012f565b634e487b7160e01b845260418652602484fd5b835162461bcd60e51b8152808401869052602760248201527f56657374696e674d61737465723a2063616c6c6572206973206e6f7420746865604482015266103637b1b5b2b960c91b6064820152608490fd5b80fd5b503461055b57602036600319011261055b576104b0610a62565b906104b9610aaf565b6001600160a01b03918216928315610509575050600180546001600160a01b031981168417909155167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b906020608492519162461bcd60e51b8352820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152fd5b8280fd5b50503461059a578160031936011261059a57602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b5080fd5b50503461059a57602036600319011261059a576105b9610a62565b6105c1610aaf565b6001600160a01b03168083526005602052908220546105de575080f35b6105e781610d2d565b507f95266445d018e5b30f957c915e91b04bb4a19bf0f8f21020a08dad9be7931df48280a280f35b50913461049357602090816003193601126104935761062c610a62565b6001600160a01b03168152600280835283822080549095839283929167ffffffffffffffff83116107105750610666868360051b01610b3d565b828152978352858320839087808b015b8584106106f257509250505082915061068d610b07565b8281520152915b85518310156106e5576106a78387610ba1565b51848101514211156106ce576106c8916106c2915190610bb5565b92610b7c565b91610694565b6106c89193926106df915190610bb5565b91610b7c565b9150918351928352820152f35b600191859161070085610b63565b8152019201920191908890610676565b634e487b7160e01b845260419052602483fd5b50503461059a578160031936011261059a5760015490516001600160a01b039091168152602090f35b8334610493578060031936011261049357610765610aaf565b600180546001600160a01b0319811690915581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b50503461059a578160031936011261059a576020906003549051908152f35b5091346104935780600319360112610493576107e2610c3f565b3381526020600281528282209082816107f9610b07565b828152015282835b835481101561088a5761081d6108178286610a7d565b50610b63565b80519084821515918261087d575b5050610841575b5061083c90610b7c565b610801565b61084b9192610bb5565b906108568185610a7d565b61086b5785815560010185905561083c610832565b634e487b7160e01b8652858852602486fd5b015142119050843861082b565b5083859181808280156108e8575b8280929181923390f1156108dc579060019183519081527f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d4853392a2555160018152f35b509051903d90823e3d90fd5b6108fc9150610898565b50503461059a57602036600319011261059a5761090d610a62565b610915610aaf565b6001600160a01b031680835260056020529082205415610933575080f35b61093c81610cb0565b507f7c5af8d36d8be103bc583da8e01d3e98f15216cc7ef38832c7550b34e8feb43a8280a280f35b50503461059a578060031936011261059a5761097e610a62565b6001600160a01b031682526002602052808220805460243591908210156109bd57906109a991610a7d565b506001815491015482519182526020820152f35b8380fd5b503461055b578260031936011261055b5760209250549051908152f35b5091346104935760203660031901126104935782358354811015610a155760209382528360018060a01b0392200154169051908152f35b634e487b7160e01b825260328452602482fd5b84903461059a578160031936011261059a576020907f00000000000000000000000000000000000000000000000000000000000000008152f35b600435906001600160a01b0382168203610a7857565b600080fd5b8054821015610a995760005260206000209060011b0190600090565b634e487b7160e01b600052603260045260246000fd5b6001546001600160a01b03163303610ac357565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b604051906040820182811067ffffffffffffffff821117610b2757604052565b634e487b7160e01b600052604160045260246000fd5b6040519190601f01601f1916820167ffffffffffffffff811183821017610b2757604052565b906001610b6e610b07565b928054845201546020830152565b6000198114610b8b5760010190565b634e487b7160e01b600052601160045260246000fd5b8051821015610a995760209160051b010190565b91908201809211610b8b57565b8115610bcc570490565b634e487b7160e01b600052601260045260246000fd5b81810292918115918404141715610b8b57565b8054600160401b811015610b2757610c1291600182018155610a7d565b919091610c29576020816001925184550151910155565b634e487b7160e01b600052600060045260246000fd5b600260005414610c50576002600055565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b600454811015610a9957600460005260206000200190600090565b600081815260056020526040812054610d2857600454600160401b811015610d14579082610d00610ce984600160409601600455610c95565b819391549060031b91821b91600019901b19161790565b905560045492815260056020522055600190565b634e487b7160e01b82526041600452602482fd5b905090565b6000818152600560205260408120549091908015610e125760001990808201818111610dfe5760045490838201918211610dea57808203610db6575b5050506004548015610da257810190610d8182610c95565b909182549160031b1b19169055600455815260056020526040812055600190565b634e487b7160e01b84526031600452602484fd5b610dd4610dc5610ce993610c95565b90549060031b1c928392610c95565b9055845260056020526040842055388080610d69565b634e487b7160e01b86526011600452602486fd5b634e487b7160e01b85526011600452602485fd5b50509056fea164736f6c6343000813000a56657374696e674d61737465723a3a636f6e7374727563746f723a2050657269";

type VestingMasterConstructorParams =
| [signer?: Signer]
Expand Down

0 comments on commit 0e62a24

Please sign in to comment.