-
Notifications
You must be signed in to change notification settings - Fork 0
/
GrantManager.sol
228 lines (190 loc) · 6.28 KB
/
GrantManager.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
/// @custom:security-contact chris.stone@cse-corp.com
/*
Run on Ropsten
Load up the MetaMask account at: https://faucet.ropsten.be/
or https://faucet.metamask.io/
or https://faucet.dimensions.network
*/
contract GrantManager is ERC20, ERC20Burnable, Ownable, Pausable {
/*
* @title A Grants Management Treasury
* @author Christopher M. Stone
* @notice You can use this contract for issuing ERC-20 tokens and tracking grant information
* @dev Set who may pause the contract
*/
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
/*
* @dev Create a struct to store grant awards
* @notice This captures all of the typical grant metadata
*/
struct AwardInfo {
string awardeeName;
address awardeeAddr;
string cageCode;
string naicsCode;
string grantNumber;
string effectiveDate;
string completionDate;
uint laborCLINValue;
uint travelCLINValue;
uint odcValue;
uint totalAwardValue;
bool completed;
}
/**
* @dev Create an array of 'AwardInfo' structs
*/
AwardInfo[] public awards;
// ****************** Start Award Mapping *****************
// Mapping from address to uint
mapping(address => uint) public myMap;
function get(address _addr) public view returns (uint) {
// Mapping always returns a value.
// If the value was never set, it will return the default value.
return myMap[_addr];
}
function set(address _addr, uint _i) public {
// Update the value at this address
myMap[_addr] = _i;
}
function remove(address _addr) public {
// Reset the value to the default value.
delete myMap[_addr];
}
// ****************** End Award Mapping *****************
// ****************** Start Payment Request *****************
struct PaymentInfo {
string grantNumber;
uint AwardIDNum; // location in array
address paymentSender;
string fileURI; // file hash
uint invLaborCLINValue;
uint invTravelCLINValue;
uint invOdcValue;
uint invTotalAwardValue;
string timeSubmitted; // get timestamp
bool successfullyPayed;
}
/**
* @dev Create an array of 'PaymentInfo' structs
*/
PaymentInfo[] public payments;
// see this for tips...
//https://solidity-by-example.org/app/erc20/
// ****************** End Payment Request *****************
// ****************** Start IPFS Behavior *****************
mapping (address => string) public userFiles;
function setFile(string memory file) external {
userFiles[msg.sender] = file;
}
// ****************** End IPFS Behavior *****************
constructor() ERC20("NSFCTokens", "NSFC") {
}
/**
* @dev Returns the number of awards in the AwardInfo array
* @notice Returns the number of awards in the AwardInfo array
*/
function getNumberAwards() public view returns (uint) {
return awards.length;
}
/**
* @dev pauses the contract
*/
function pause() public onlyOwner {
_pause();
}
/**
* @dev unpauses the contract
*/
function unpause() public onlyOwner {
_unpause();
}
/**
// saving this for when I'm ready to shadow USD
// Let's keep it 18 decimals for now, and round it for display in javascript
function decimals() public view virtual override returns (uint8) {
return 2;
}
*/
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount * 10 ** decimals());
// _mint(to, amount);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount)
internal
whenNotPaused
override
{
super._beforeTokenTransfer(from, to, amount);
}
/**
* @dev creates a new grant and pushes the struct to the end of the awards array
* only the contract Owner can create a new grant
*/
function createGrant(string memory _awardeeName,
address _awardeeAddr,
string memory _cageCode,
string memory _naicsCode,
string memory _grantNumber,
string memory _effectiveDate,
string memory _completionDate,
uint _laborCLINValue,
uint _travelCLINValue,
uint _odcValue,
uint _totalAwardValue
) public onlyOwner {
awards.push(AwardInfo(
_awardeeName,
_awardeeAddr,
_cageCode,
_naicsCode,
_grantNumber,
_effectiveDate,
_completionDate,
_laborCLINValue,
_travelCLINValue,
_odcValue,
_totalAwardValue,
false
));
mint(_awardeeAddr, _totalAwardValue);
increaseAllowance(_awardeeAddr, _totalAwardValue);
}
/**
* Fallback function - Called if other functions don't match call or
* sent ether without data
* Typically, called when invalid data is sent
* Added so ether sent to this contract is reverted if the contract fails
* otherwise, the sender's money is transferred to contract
*/
fallback () external payable {
revert();
}
}