@gooddollar/goodprotocol 1.0.18 → 1.0.19-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/abis/GReputation.min.json +1 -1
- package/artifacts/abis/GoodAaveStaking.min.json +1 -1
- package/artifacts/abis/GoodAaveStakingV2.min.json +1 -1
- package/artifacts/abis/GoodCompoundStaking.min.json +1 -1
- package/artifacts/abis/GoodCompoundStakingTest.min.json +1 -1
- package/artifacts/abis/GoodCompoundStakingV2.min.json +1 -1
- package/artifacts/abis/UpgradableMock3.min.json +1 -0
- package/artifacts/abis/UpgradableMock4.min.json +1 -0
- package/artifacts/contracts/DAOStackInterfaces.sol/Avatar.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/Controller.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/GlobalConstraintInterface.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/IntVoteInterface.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/ReputationInterface.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/SchemeRegistrar.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/AggregatorV3Interface.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/ERC20.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IAaveIncentivesController.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IAdminWallet.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IDonationStaking.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IERC2917.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IFirstClaimPool.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IGoodDollar.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IGoodStaking.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IHasRouter.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IIdentity.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/ILendingPool.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/INameService.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IUBIScheme.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/ProxyAdmin.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/Reserve.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/Staking.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/Uniswap.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/UniswapFactory.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/UniswapPair.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/cERC20.dbg.json +1 -1
- package/artifacts/contracts/governance/ClaimersDistribution.sol/ClaimersDistribution.dbg.json +1 -1
- package/artifacts/contracts/governance/ClaimersDistribution.sol/ClaimersDistribution.json +2 -2
- package/artifacts/contracts/governance/CompoundVotingMachine.sol/CompoundVotingMachine.dbg.json +1 -1
- package/artifacts/contracts/governance/GReputation.sol/GReputation.dbg.json +1 -1
- package/artifacts/contracts/governance/GReputation.sol/GReputation.json +15 -2
- package/artifacts/contracts/governance/GovernanceStaking.sol/GovernanceStaking.dbg.json +1 -1
- package/artifacts/contracts/governance/MultiBaseGovernanceShareField.sol/MultiBaseGovernanceShareField.dbg.json +1 -1
- package/artifacts/contracts/governance/Reputation.sol/Reputation.dbg.json +1 -1
- package/artifacts/contracts/governance/Reputation.sol/Reputation.json +2 -2
- package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.dbg.json +1 -1
- package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.json +2 -2
- package/artifacts/contracts/mocks/AaveMock.sol/AaveMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/AaveUSDMockOracle.sol/AaveUSDMockOracle.dbg.json +1 -1
- package/artifacts/contracts/mocks/BatUSDMockOracle.sol/BatUSDMockOracle.dbg.json +1 -1
- package/artifacts/contracts/mocks/CompUsdMockOracle.sol/CompUSDMockOracle.dbg.json +1 -1
- package/artifacts/contracts/mocks/DAIMock.sol/DAIMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/DaiEthPriceMockOracle.sol/DaiEthPriceMockOracle.dbg.json +1 -1
- package/artifacts/contracts/mocks/DecimalsMock.sol/DecimalsMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/EthUSDMockOracle.sol/EthUSDMockOracle.dbg.json +1 -1
- package/artifacts/contracts/mocks/GasPriceMockOracle.sol/GasPriceMockOracle.dbg.json +1 -1
- package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.json +6 -6
- package/artifacts/contracts/mocks/GoodFundManagerTest.sol/GoodFundManagerTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/IncentiveControllerMock.sol/IncentiveControllerMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/LendingPoolMock.sol/LendingPoolMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/OverMintTester.sol/OverMintTester.dbg.json +1 -1
- package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.dbg.json +1 -1
- package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.json +2 -2
- package/artifacts/contracts/mocks/SixteenDecimalsTokenMock.sol/SixteenDecimalsTokenMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/SwapHelperTest.sol/SwapHelperTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/TwentyDecimalsTokenMock.sol/TwentyDecimalsTokenMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock.json +2 -2
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock2.dbg.json +1 -1
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock2.json +2 -2
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock3.dbg.json +4 -0
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock3.json +172 -0
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock4.dbg.json +4 -0
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock4.json +172 -0
- package/artifacts/contracts/mocks/UsdcMock.sol/USDCMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cBATMock.sol/cBATMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDAILowWorthMock.sol/cDAILowWorthMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDAIMock.sol/cDAIMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDAINonMintableMock.sol/cDAINonMintableMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDecimalsMock.sol/cDecimalsMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cSDTMock.sol/cSDTMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cUSDCMock.sol/cUSDCMock.dbg.json +1 -1
- package/artifacts/contracts/reserve/ExchangeHelper.sol/ExchangeHelper.dbg.json +1 -1
- package/artifacts/contracts/reserve/GoodMarketMaker.sol/GoodMarketMaker.dbg.json +1 -1
- package/artifacts/contracts/reserve/GoodReserveCDai.sol/ContributionCalc.dbg.json +1 -1
- package/artifacts/contracts/reserve/GoodReserveCDai.sol/GoodReserveCDai.dbg.json +1 -1
- package/artifacts/contracts/staking/BaseShareField.sol/BaseShareField.dbg.json +1 -1
- package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.dbg.json +1 -1
- package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.json +2 -2
- package/artifacts/contracts/staking/GoodFundManager.sol/GoodFundManager.dbg.json +1 -1
- package/artifacts/contracts/staking/SimpleStaking.sol/SimpleStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/UniswapV2SwapHelper.sol/UniswapV2SwapHelper.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.json +2 -2
- package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.json +3 -3
- package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.json +3 -3
- package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.json +2 -2
- package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.json +4 -4
- package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.json +4 -4
- package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.dbg.json +1 -1
- package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.json +2 -2
- package/artifacts/contracts/utils/BancorFormula.sol/BancorFormula.dbg.json +1 -1
- package/artifacts/contracts/utils/BulkProof.sol/BulkProof.dbg.json +1 -1
- package/artifacts/contracts/utils/BulkProof.sol/BulkProof.json +2 -2
- package/artifacts/contracts/utils/DAOContract.sol/DAOContract.dbg.json +1 -1
- package/artifacts/contracts/utils/DAOUpgradeableContract.sol/DAOUpgradeableContract.dbg.json +1 -1
- package/artifacts/contracts/utils/DSMath.sol/DSMath.dbg.json +1 -1
- package/artifacts/contracts/utils/DataTypes.sol/DataTypes.dbg.json +1 -1
- package/artifacts/contracts/utils/MultiCall.sol/Multicall.dbg.json +1 -1
- package/artifacts/contracts/utils/NameService.sol/NameService.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgrade.sol/OldMarketMaker.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgrade.sol/ProtocolUpgrade.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgradeFuse.sol/ProtocolUpgradeFuse.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgradeFuseRecover.sol/ProtocolUpgradeFuseRecover.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgradeRecover.sol/ProtocolUpgradeRecover.dbg.json +1 -1
- package/artifacts/contracts/utils/ProxyFactory1967.sol/ERC1967Proxy.dbg.json +1 -1
- package/artifacts/contracts/utils/ProxyFactory1967.sol/ProxyFactory1967.dbg.json +1 -1
- package/artifacts/contracts/utils/ReputationTestHelper.sol/ReputationTestHelper.dbg.json +1 -1
- package/artifacts/contracts/utils/ReputationTestHelper.sol/ReputationTestHelper.json +2 -2
- package/contracts/governance/GReputation.sol +8 -0
- package/contracts/governance/Reputation.sol +5 -3
- package/contracts/mocks/UpgradableMocks.sol +18 -0
- package/contracts/staking/SimpleStaking.sol +2 -1
- package/contracts/staking/SimpleStakingV2.sol +2 -1
- package/hardhat.config.ts +63 -8
- package/package.json +7 -5
- package/releases/deployment.json +11 -0
- package/scripts/multichain-deploy/basicdao-deploy.ts +256 -0
- package/scripts/multichain-deploy/helpers.ts +96 -0
- package/test/governance/ClaimersDistribution.test.ts +6 -6
- package/test/governance/CompoundVotingMachine.daoscheme.ts +14 -1
- package/test/governance/CompoundVotingMachine.guardian.test.ts +11 -1
- package/test/governance/GReputation.test.ts +32 -1
- package/test/governance/StakersDistribution.test.ts +62 -1
- package/test/helpers.ts +15 -0
- package/test/reserve/GoodMarketMaker.test.ts +11 -0
- package/test/reserve/GoodReserveCDai.gdx.test.ts +23 -8
- package/test/reserve/GoodReserveCDai.test.ts +37 -2
- package/test/staking/CompoundStakingFactory.test.ts +31 -0
- package/test/staking/DonationsStaking.test.ts +99 -2
- package/test/staking/GoodAaveStakingFactory.test.ts +36 -1
- package/test/staking/SimpleDAIStaking.test.ts +52 -2
- package/test/staking/StakingRewards.test.ts +38 -0
- package/test/staking/UsdcAaveStaking.test.ts +45 -19
- package/test/ubi/UBIScheme.test.ts +68 -0
- package/test/utils/DAOUpgradeableContract.test.ts +47 -0
- package/test/utils/NameService.test.ts +50 -55
- package/test/utils/ProxyFactory.test.ts +17 -0
- package/yarn.lock +607 -119
- package/artifacts/abis/FuseFaucet.min.json +0 -1
- package/artifacts/abis/InvitesV1.min.json +0 -1
- package/artifacts/contracts/unaudited-foundation/FuseFaucet.sol/FuseFaucet.dbg.json +0 -4
- package/artifacts/contracts/unaudited-foundation/FuseFaucet.sol/FuseFaucet.json +0 -200
- package/artifacts/contracts/unaudited-foundation/InvitesV1.sol/InvitesV1.dbg.json +0 -4
- package/artifacts/contracts/unaudited-foundation/InvitesV1.sol/InvitesV1.json +0 -486
- package/contracts/unaudited-foundation/FuseFaucet.sol +0 -120
- package/contracts/unaudited-foundation/InvitesV1.sol +0 -304
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
|
|
3
|
-
pragma solidity >=0.6.0;
|
|
4
|
-
|
|
5
|
-
pragma experimental ABIEncoderV2;
|
|
6
|
-
|
|
7
|
-
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
8
|
-
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
|
|
9
|
-
import "../Interfaces.sol";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @title InvitesV1 contract that handles invites with pre allocated bounty pool
|
|
13
|
-
* 1.1 adds invitee bonus
|
|
14
|
-
*/
|
|
15
|
-
contract InvitesV1 is Initializable {
|
|
16
|
-
using SafeMathUpgradeable for uint256;
|
|
17
|
-
|
|
18
|
-
struct Stats {
|
|
19
|
-
uint256 totalApprovedInvites;
|
|
20
|
-
uint256 totalBountiesPaid;
|
|
21
|
-
uint256 totalInvited;
|
|
22
|
-
uint256[5] __reserevedSpace;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
struct User {
|
|
26
|
-
address invitedBy;
|
|
27
|
-
bytes32 inviteCode;
|
|
28
|
-
bool bountyPaid;
|
|
29
|
-
address[] invitees;
|
|
30
|
-
address[] pending;
|
|
31
|
-
uint256 level;
|
|
32
|
-
uint256 levelStarted;
|
|
33
|
-
uint256 totalApprovedInvites;
|
|
34
|
-
uint256 totalEarned;
|
|
35
|
-
uint256 joinedAt;
|
|
36
|
-
uint256[5] __reserevedSpace;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
struct Level {
|
|
40
|
-
uint256 toNext;
|
|
41
|
-
uint256 bounty; //in G$ cents ie 2 decimals
|
|
42
|
-
uint256 daysToComplete;
|
|
43
|
-
uint256[5] __reserevedSpace;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
mapping(bytes32 => address) public codeToUser;
|
|
47
|
-
mapping(address => User) public users;
|
|
48
|
-
address payable public avatar;
|
|
49
|
-
|
|
50
|
-
mapping(uint256 => Level) public levels;
|
|
51
|
-
|
|
52
|
-
address public owner;
|
|
53
|
-
IIdentity public identity;
|
|
54
|
-
cERC20 public goodDollar;
|
|
55
|
-
bool public active;
|
|
56
|
-
Stats public stats;
|
|
57
|
-
|
|
58
|
-
bool public levelExpirationEnabled;
|
|
59
|
-
|
|
60
|
-
event InviteeJoined(address indexed inviter, address indexed invitee);
|
|
61
|
-
event InviterBounty(
|
|
62
|
-
address indexed inviter,
|
|
63
|
-
address indexed invitee,
|
|
64
|
-
uint256 bountyPaid,
|
|
65
|
-
uint256 inviterLevel,
|
|
66
|
-
bool earnedLevel
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
modifier ownerOrAvatar() {
|
|
70
|
-
require(
|
|
71
|
-
msg.sender == owner || msg.sender == avatar,
|
|
72
|
-
"Only owner or avatar can perform this action"
|
|
73
|
-
);
|
|
74
|
-
_;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
modifier onlyAvatar() {
|
|
78
|
-
require(msg.sender == avatar, "Only DAO avatar can perform this action");
|
|
79
|
-
_;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
modifier isActive() {
|
|
83
|
-
require(active);
|
|
84
|
-
_;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function initialize(
|
|
88
|
-
address payable _avatar,
|
|
89
|
-
address _identity,
|
|
90
|
-
address _gd,
|
|
91
|
-
uint256 level0Bounty
|
|
92
|
-
) public initializer {
|
|
93
|
-
owner = msg.sender;
|
|
94
|
-
identity = IIdentity(_identity);
|
|
95
|
-
active = true;
|
|
96
|
-
Level storage lvl = levels[0];
|
|
97
|
-
lvl.bounty = level0Bounty;
|
|
98
|
-
goodDollar = cERC20(_gd);
|
|
99
|
-
avatar = _avatar;
|
|
100
|
-
levelExpirationEnabled = false;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function setLevelExpirationEnabled(bool _isEnabled) public ownerOrAvatar {
|
|
104
|
-
levelExpirationEnabled = _isEnabled;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function join(bytes32 _myCode, bytes32 _inviterCode) public isActive {
|
|
108
|
-
User storage user = users[msg.sender];
|
|
109
|
-
require(
|
|
110
|
-
codeToUser[_myCode] == address(0) || codeToUser[_myCode] == msg.sender,
|
|
111
|
-
"invite code already in use"
|
|
112
|
-
);
|
|
113
|
-
address inviter = codeToUser[_inviterCode];
|
|
114
|
-
//allow user to set inviter if doesnt have one
|
|
115
|
-
require(
|
|
116
|
-
user.inviteCode == 0x0 ||
|
|
117
|
-
(user.invitedBy == address(0) && inviter != address(0)),
|
|
118
|
-
"user already joined"
|
|
119
|
-
);
|
|
120
|
-
if (user.inviteCode == 0x0) {
|
|
121
|
-
user.inviteCode = _myCode;
|
|
122
|
-
user.levelStarted = block.timestamp;
|
|
123
|
-
user.joinedAt = block.timestamp;
|
|
124
|
-
codeToUser[_myCode] = msg.sender;
|
|
125
|
-
}
|
|
126
|
-
if (inviter != address(0)) {
|
|
127
|
-
user.invitedBy = inviter;
|
|
128
|
-
User storage inviterUser = users[inviter];
|
|
129
|
-
inviterUser.invitees.push(msg.sender);
|
|
130
|
-
inviterUser.pending.push(msg.sender);
|
|
131
|
-
stats.totalInvited += 1;
|
|
132
|
-
}
|
|
133
|
-
emit InviteeJoined(inviter, msg.sender);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function canCollectBountyFor(address _invitee) public view returns (bool) {
|
|
137
|
-
User storage user = users[_invitee];
|
|
138
|
-
User storage inviter = users[user.invitedBy];
|
|
139
|
-
uint256 daysToComplete = levels[inviter.level].daysToComplete;
|
|
140
|
-
bool isLevelExpired = levelExpirationEnabled == true &&
|
|
141
|
-
daysToComplete > 0 &&
|
|
142
|
-
daysToComplete < user.joinedAt.sub(inviter.levelStarted).div(1 days);
|
|
143
|
-
|
|
144
|
-
return
|
|
145
|
-
!user.bountyPaid &&
|
|
146
|
-
user.invitedBy != address(0) &&
|
|
147
|
-
identity.isWhitelisted(_invitee) &&
|
|
148
|
-
identity.isWhitelisted(user.invitedBy) &&
|
|
149
|
-
isLevelExpired == false;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function getInvitees(address _inviter)
|
|
153
|
-
public
|
|
154
|
-
view
|
|
155
|
-
returns (address[] memory)
|
|
156
|
-
{
|
|
157
|
-
return users[_inviter].invitees;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function getPendingInvitees(address _inviter)
|
|
161
|
-
public
|
|
162
|
-
view
|
|
163
|
-
returns (address[] memory)
|
|
164
|
-
{
|
|
165
|
-
address[] memory pending = users[_inviter].pending;
|
|
166
|
-
uint256 cur = 0;
|
|
167
|
-
uint256 total = 0;
|
|
168
|
-
for (uint256 i; i < pending.length; i++) {
|
|
169
|
-
if (!users[pending[i]].bountyPaid) {
|
|
170
|
-
total++;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
address[] memory result = new address[](total);
|
|
175
|
-
|
|
176
|
-
for (uint256 i; i < pending.length; i++) {
|
|
177
|
-
if (!users[pending[i]].bountyPaid) {
|
|
178
|
-
result[cur] = pending[i];
|
|
179
|
-
cur++;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return result;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function getPendingBounties(address _inviter) public view returns (uint256) {
|
|
187
|
-
address[] memory pending = users[_inviter].pending;
|
|
188
|
-
uint256 total = 0;
|
|
189
|
-
for (uint256 i; i < pending.length; i++) {
|
|
190
|
-
if (canCollectBountyFor(pending[i])) {
|
|
191
|
-
total++;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return total;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* @dev pay bounty for the inviter of _invitee
|
|
199
|
-
* invitee need to be whitelisted
|
|
200
|
-
*/
|
|
201
|
-
function bountyFor(address _invitee) public isActive {
|
|
202
|
-
require(canCollectBountyFor(_invitee), "user not elligble for bounty yet");
|
|
203
|
-
return _bountyFor(_invitee);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function _bountyFor(address _invitee) internal {
|
|
207
|
-
address invitedBy = users[_invitee].invitedBy;
|
|
208
|
-
uint256 joinedAt = users[_invitee].joinedAt;
|
|
209
|
-
Level memory level = levels[users[invitedBy].level];
|
|
210
|
-
|
|
211
|
-
bool isLevelExpired = level.daysToComplete > 0 &&
|
|
212
|
-
joinedAt > users[invitedBy].levelStarted && //prevent overflow in subtraction
|
|
213
|
-
level.daysToComplete <
|
|
214
|
-
joinedAt.sub(users[invitedBy].levelStarted).div(1 days); //how long after level started did invitee join
|
|
215
|
-
|
|
216
|
-
users[_invitee].bountyPaid = true;
|
|
217
|
-
users[invitedBy].totalApprovedInvites += 1;
|
|
218
|
-
users[invitedBy].totalEarned += level.bounty;
|
|
219
|
-
stats.totalApprovedInvites += 1;
|
|
220
|
-
stats.totalBountiesPaid += level.bounty;
|
|
221
|
-
|
|
222
|
-
bool earnedLevel = false;
|
|
223
|
-
if (
|
|
224
|
-
level.toNext > 0 &&
|
|
225
|
-
users[invitedBy].totalApprovedInvites >= level.toNext &&
|
|
226
|
-
isLevelExpired == false
|
|
227
|
-
) {
|
|
228
|
-
users[invitedBy].level += 1;
|
|
229
|
-
users[invitedBy].levelStarted = block.timestamp;
|
|
230
|
-
earnedLevel = true;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
goodDollar.transfer(invitedBy, level.bounty);
|
|
234
|
-
goodDollar.transfer(_invitee, level.bounty.div(2)); //pay invitee half the bounty
|
|
235
|
-
|
|
236
|
-
emit InviterBounty(
|
|
237
|
-
invitedBy,
|
|
238
|
-
_invitee,
|
|
239
|
-
level.bounty,
|
|
240
|
-
users[invitedBy].level,
|
|
241
|
-
earnedLevel
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
@dev collect bounties for invitees by msg.sender that are now whitelisted
|
|
247
|
-
*/
|
|
248
|
-
function collectBounties() public isActive {
|
|
249
|
-
User storage inviter = users[msg.sender];
|
|
250
|
-
|
|
251
|
-
for (uint256 i = 0; i < inviter.pending.length; i++) {
|
|
252
|
-
if (gasleft() < 340000) return;
|
|
253
|
-
address pending = inviter.pending[i];
|
|
254
|
-
if (canCollectBountyFor(pending)) {
|
|
255
|
-
_bountyFor(pending);
|
|
256
|
-
}
|
|
257
|
-
if (users[pending].bountyPaid) {
|
|
258
|
-
//if still elements in array move last item to current position
|
|
259
|
-
if (inviter.pending.length - 1 > i) {
|
|
260
|
-
inviter.pending[i] = inviter.pending[inviter.pending.length - 1];
|
|
261
|
-
|
|
262
|
-
//force loop to do current position again so we dont miss the just moved last item
|
|
263
|
-
i--;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
//extract item from pendig array
|
|
267
|
-
inviter.pending.pop();
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function setLevel(
|
|
273
|
-
uint256 _lvl,
|
|
274
|
-
uint256 _toNext,
|
|
275
|
-
uint256 _bounty,
|
|
276
|
-
uint256 _daysToComplete
|
|
277
|
-
) public ownerOrAvatar {
|
|
278
|
-
Level storage lvl = levels[_lvl];
|
|
279
|
-
lvl.toNext = _toNext;
|
|
280
|
-
lvl.daysToComplete = _daysToComplete;
|
|
281
|
-
lvl.bounty = _bounty;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
function setActive(bool _active) public ownerOrAvatar {
|
|
285
|
-
active = _active;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function end() public ownerOrAvatar isActive {
|
|
289
|
-
uint256 gdBalance = goodDollar.balanceOf(address(this));
|
|
290
|
-
goodDollar.transfer(avatar, gdBalance);
|
|
291
|
-
avatar.transfer(address(this).balance);
|
|
292
|
-
active = false;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* @dev
|
|
297
|
-
* 1.2.0 - final changes before release
|
|
298
|
-
* 1.3.0 - allow to set inviter later
|
|
299
|
-
* 1.4.0 - improve gas for bounty collection
|
|
300
|
-
*/
|
|
301
|
-
function version() public pure returns (string memory) {
|
|
302
|
-
return "1.4.0";
|
|
303
|
-
}
|
|
304
|
-
}
|