-
Notifications
You must be signed in to change notification settings - Fork 0
/
contract.sol
41 lines (35 loc) · 1.6 KB
/
contract.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
pragma solidity ^0.8.0;
import "https://github.com/open-contracts/protocol/blob/main/solidity_contracts/OpenContractRopsten.sol";
contract ReforestationCommitments is OpenContract {
uint32 public rainforestKm2In2021 = 3470909;
uint8 public lastRewardedYear = 21;
uint256[] public deposits;
uint256[] public valuesPerKm2PerYear;
constructor() {
setOracleHash(this.measureRainforest.selector, 0x80d414e7627bc411045ab1b731006fd2a2c458853f61cf27fcd9fb6a0f27a828);
}
function deposit(uint256 valuePerKm2PerYear) public payable {
deposits.push(msg.value);
valuesPerKm2PerYear.push(valuePerKm2PerYear);
}
function measureRainforest(uint256 rainforestKm2, uint8 mo, uint8 yr) public requiresOracle {
require(mo == 1, "The contract currently rewards rainforest size yearly, every January.");
require(yr > lastRewardedYear, "The reward for the submitted year was already claimed.");
lastRewardedYear += 1;
uint256 reward = 0;
for (uint32 i=0; i<deposits.length; i++) {
uint256 valueGenerated = valuesPerKm2PerYear[i] * (rainforestKm2 - rainforestKm2In2021);
if (valueGenerated > deposits[i]) {
reward += deposits[i];
deposits[i] = 0;
} else {
reward += valueGenerated;
deposits[i] -= valueGenerated;
}
}
PayATwitterAccount(0x507D995e5E1aDf0e6B77BD18AC15F8Aa747B6D07).deposit{value:reward}("govbrazil");
}
}
interface PayATwitterAccount {
function deposit(string memory twitterHandle) external payable;
}