mirror of
https://github.com/Instadapp/InstaContract.git
synced 2024-07-29 22:47:45 +00:00
Start using SafeMath and IERC20 interface from OpenZeppelin
This commit is contained in:
parent
831101d965
commit
8d706d8ae0
|
@ -5,17 +5,14 @@
|
|||
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
|
||||
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
|
||||
|
||||
interface AddressRegistry {
|
||||
function getAddr(string name) external returns(address);
|
||||
function isApprovedResolver(address user) external returns(bool);
|
||||
}
|
||||
|
||||
interface token {
|
||||
function approve(address spender, uint256 value) external returns (bool);
|
||||
function transfer(address receiver, uint amount) external returns (bool);
|
||||
function transferFrom(address from, address to, uint amount) external returns (bool);
|
||||
}
|
||||
|
||||
|
||||
contract Registry {
|
||||
|
||||
|
@ -40,6 +37,9 @@ contract Registry {
|
|||
|
||||
contract AssetDB is Registry {
|
||||
|
||||
using SafeMath for uint;
|
||||
using SafeMath for uint256;
|
||||
|
||||
mapping(address => mapping(address => uint)) balances;
|
||||
address eth = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee;
|
||||
|
||||
|
@ -53,21 +53,21 @@ contract AssetDB is Registry {
|
|||
|
||||
function deposit(address tknAddr, uint amount) public payable {
|
||||
if (msg.value > 0) {
|
||||
balances[msg.sender][eth] += msg.value;
|
||||
balances[msg.sender][eth] = balances[msg.sender][eth].add(msg.value);
|
||||
} else {
|
||||
token tokenFunctions = token(tknAddr);
|
||||
IERC20 tokenFunctions = IERC20(tknAddr);
|
||||
tokenFunctions.transferFrom(msg.sender, address(this), amount);
|
||||
balances[msg.sender][tknAddr] += amount;
|
||||
balances[msg.sender][tknAddr] = balances[msg.sender][tknAddr].add(amount);
|
||||
}
|
||||
}
|
||||
|
||||
function withdraw(address tknAddr, uint amount) public {
|
||||
require(balances[msg.sender][tknAddr] >= amount, "Insufficient Balance");
|
||||
balances[msg.sender][tknAddr] -= amount;
|
||||
balances[msg.sender][tknAddr] = balances[msg.sender][tknAddr].sub(amount);
|
||||
if (tknAddr == eth) {
|
||||
msg.sender.transfer(amount);
|
||||
} else {
|
||||
token tokenFunctions = token(tknAddr);
|
||||
IERC20 tokenFunctions = IERC20(tknAddr);
|
||||
tokenFunctions.transfer(msg.sender, amount);
|
||||
}
|
||||
}
|
||||
|
@ -80,9 +80,9 @@ contract AssetDB is Registry {
|
|||
) public onlyAllowedResolver(user)
|
||||
{
|
||||
if (credit) {
|
||||
balances[user][tokenAddr] += amount;
|
||||
balances[user][tokenAddr] = balances[user][tokenAddr].add(amount);
|
||||
} else {
|
||||
balances[user][tokenAddr] -= amount;
|
||||
balances[user][tokenAddr] = balances[user][tokenAddr].sub(amount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,10 +96,10 @@ contract AssetDB is Registry {
|
|||
if (tokenAddress == eth) {
|
||||
sendTo.transfer(amount);
|
||||
} else {
|
||||
token tokenFunctions = token(tokenAddress);
|
||||
IERC20 tokenFunctions = IERC20(tokenAddress);
|
||||
tokenFunctions.transfer(sendTo, amount);
|
||||
}
|
||||
balances[user][tokenAddress] -= amount;
|
||||
balances[user][tokenAddress] = balances[user][tokenAddress].sub(amount);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
"openzeppelin-solidity": "^2.0.0",
|
||||
"prettier": "^1.14.3",
|
||||
"truffle": "^5.0.0-beta.0",
|
||||
"webpack": "^4.22.0",
|
||||
"webpack": "^4.23.1",
|
||||
"truffle-hdwallet-provider": "^1.0.0-web3one.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -44,13 +44,13 @@
|
|||
"chai-as-promised": "7.1.1",
|
||||
"chai-bignumber": "2.0.2",
|
||||
"coveralls": "3.0.2",
|
||||
"eslint": "5.7.0",
|
||||
"eslint": "5.8.0",
|
||||
"eslint-config-prettier": "^3.1.0",
|
||||
"eslint-config-standard": "^12.0.0",
|
||||
"eslint-plugin-babel": "^5.2.1",
|
||||
"eslint-plugin-compat": "^2.6.2",
|
||||
"eslint-plugin-import": "2.14.0",
|
||||
"eslint-plugin-node": "7.0.1",
|
||||
"eslint-plugin-node": "8.0.0",
|
||||
"eslint-plugin-prettier": "^3.0.0",
|
||||
"eslint-plugin-promise": "4.0.1",
|
||||
"eslint-plugin-security": "^1.4.0",
|
||||
|
|
Loading…
Reference in New Issue
Block a user