-
Notifications
You must be signed in to change notification settings - Fork 356
/
OdisPayments.sol
75 lines (65 loc) · 2.41 KB
/
OdisPayments.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pragma solidity ^0.5.13;
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/SafeERC20.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "./interfaces/IOdisPayments.sol";
import "../common/interfaces/ICeloVersionedContract.sol";
import "../common/Initializable.sol";
import "../common/UsingRegistryV2.sol";
import "../common/libraries/ReentrancyGuard.sol";
/**
* @title Stores balance to be used for ODIS quota calculation.
*/
contract OdisPayments is
IOdisPayments,
ICeloVersionedContract,
ReentrancyGuard,
Ownable,
Initializable,
UsingRegistryV2
{
using SafeMath for uint256;
using SafeERC20 for IERC20;
event PaymentMade(address indexed account, uint256 valueInCUSD);
// Store amount sent (all time) from account to this contract.
// Values in totalPaidCUSD should only ever be incremented, since ODIS relies
// on all-time paid balance to compute every quota.
mapping(address => uint256) public totalPaidCUSD;
/**
* @notice Sets initialized == true on implementation contracts.
* @param test Set to true to skip implementation initialization.
*/
constructor(bool test) public Initializable(test) {}
/**
* @notice Returns the storage, major, minor, and patch version of the contract.
* @return Storage version of the contract.
* @return Major version of the contract.
* @return Minor version of the contract.
* @return Patch version of the contract.
*/
function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) {
return (1, 1, 0, 0);
}
/**
* @notice Used in place of the constructor to allow the contract to be upgradable via proxy.
*/
function initialize() external initializer {
_transferOwnership(msg.sender);
}
/**
* @notice Sends cUSD to this contract to pay for ODIS quota (for queries).
* @param account The account whose balance to increment.
* @param value The amount in cUSD to pay.
* @dev Throws if cUSD transfer fails.
*/
function payInCUSD(address account, uint256 value) external nonReentrant {
IERC20(registryContract.getAddressForOrDie(STABLE_TOKEN_REGISTRY_ID)).safeTransferFrom(
msg.sender,
address(this),
value
);
totalPaidCUSD[account] = totalPaidCUSD[account].add(value);
emit PaymentMade(account, value);
}
}