Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make modifications for transferAllocation function #41

Merged
merged 34 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2d09249
make modifications for transferAllocation function
divine-comedian Jan 9, 2024
059ce20
forge fmt
divine-comedian Jan 9, 2024
4d74c18
Merge branch 'develop' into modify-allocation-functions
aminlatifi Jan 23, 2024
afa189a
fix typo in import
divine-comedian Jan 31, 2024
e15fece
add internal transferAllocation function, remove safemath
divine-comedian Feb 9, 2024
b7f27a8
add more checks from review
divine-comedian Feb 15, 2024
4162390
forge fmt
divine-comedian Feb 15, 2024
321d2c6
add comment to tranferAllocation
divine-comedian Feb 16, 2024
a98fd5a
test fix
divine-comedian Feb 16, 2024
9ce32b6
explcitly set node-version
divine-comedian Feb 16, 2024
61908de
syntax
divine-comedian Feb 16, 2024
51d4195
specify node 20
divine-comedian Feb 16, 2024
3e4dafc
Update slither.yml
divine-comedian Feb 16, 2024
8b0058a
Update slither.yml
divine-comedian Feb 16, 2024
7933fdc
Update slither.yml
divine-comedian Feb 16, 2024
abcd659
Update slither.yml
divine-comedian Feb 16, 2024
1c30d00
Update slither.yml
divine-comedian Feb 16, 2024
4ada5ab
add sendPraise to interface, forge fmt, remove some checks
divine-comedian Feb 19, 2024
ef0e40c
add sendPraise to interface, forge fmt, remove some checks
divine-comedian Feb 19, 2024
e1be749
Merge branch 'modify-allocation-functions' of github.com:Giveth/givpo…
divine-comedian Feb 19, 2024
5c99dd7
revert tokendistro changes
divine-comedian Feb 19, 2024
5e9c632
remove checks from Griff's feedback
divine-comedian Feb 19, 2024
9b41730
add latest version of token distro
divine-comedian Feb 20, 2024
021dc01
forge fmt, missing override on praise
divine-comedian Feb 20, 2024
1fcb74c
Moved changes to the same TokenDistro contract
aminlatifi Mar 3, 2024
ee655a7
Reverted slither changes
aminlatifi Mar 3, 2024
e81bd24
Upgrade dependencies
aminlatifi Mar 3, 2024
2b377b5
returned slither action back
aminlatifi Mar 3, 2024
2a4e88e
Move to new slither config
aminlatifi Mar 3, 2024
530b742
Upgraded slither action
aminlatifi Mar 3, 2024
64b9f23
Modified sliter action
aminlatifi Mar 3, 2024
579b40d
Modified slither action
aminlatifi Mar 3, 2024
61a1315
Merge branch 'develop' into modify-allocation-functions
aminlatifi Mar 3, 2024
6e5b328
Removed a repetitive function definition
aminlatifi Mar 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions .github/workflows/slither.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,26 @@ on:
branches:
- main
pull_request:

env:
FOUNDRY_PROFILE: ci

jobs:
analyze:
name: Slither check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Install deps
run: |
forge --version
forge install

- name: Run Slither
uses: crytic/slither-action@main
uses: crytic/slither-action@v0.3.1
id: slither
continue-on-error: true
with:
sarif: results.sarif
target: 'contracts/'
target: "./"
fail-on: none

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.slither.outputs.sarif }}
79 changes: 38 additions & 41 deletions contracts/TokenDistro.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ contract TokenDistro is Initializable, IDistro, AccessControlEnumerableUpgradeab
*/
event GivBackPaid(address distributor);

/**
* @dev Emitted when the DISTRIBUTOR allocate an amount of praise rewards to a recipient
*/
event PraiseRewardPaid(address distributor);

/**
* @dev Emitted when the duration is changed
*/
Expand Down Expand Up @@ -166,7 +171,6 @@ contract TokenDistro is Initializable, IDistro, AccessControlEnumerableUpgradeab
*/
function _allocate(address recipient, uint256 amount, bool claim) internal {
require(!hasRole(DISTRIBUTOR_ROLE, recipient), 'TokenDistro::allocate: DISTRIBUTOR_NOT_VALID_RECIPIENT');

balances[msg.sender].allocatedTokens = balances[msg.sender].allocatedTokens - amount;

balances[recipient].allocatedTokens = balances[recipient].allocatedTokens + amount;
Expand All @@ -191,9 +195,10 @@ contract TokenDistro is Initializable, IDistro, AccessControlEnumerableUpgradeab
* Unlike allocate method it doesn't claim recipients available balance
*/
function _allocateMany(address[] memory recipients, uint256[] memory amounts) internal onlyDistributor {
require(recipients.length == amounts.length, 'TokenDistro::allocateMany: INPUT_LENGTH_NOT_MATCH');
uint256 length = recipients.length;
require(length == amounts.length, 'TokenDistro::allocateMany: INPUT_LENGTH_NOT_MATCH');

for (uint256 i = 0; i < recipients.length; i++) {
for (uint256 i = 0; i < length; i++) {
_allocate(recipients[i], amounts[i], false);
}
}
Expand All @@ -207,6 +212,11 @@ contract TokenDistro is Initializable, IDistro, AccessControlEnumerableUpgradeab
emit GivBackPaid(msg.sender);
}

function sendPraiseRewards(address[] memory recipients, uint256[] memory amounts) external override {
_allocateMany(recipients, amounts);
emit PraiseRewardPaid(msg.sender);
}

/**
* Function that allows a recipient to change its address
* @dev The change can only be made to an address that has not previously received an allocation &
Expand All @@ -216,23 +226,7 @@ contract TokenDistro is Initializable, IDistro, AccessControlEnumerableUpgradeab
*
*/
function changeAddress(address newAddress) external override {
require(
balances[newAddress].allocatedTokens == 0 && balances[newAddress].claimed == 0,
'TokenDistro::changeAddress: ADDRESS_ALREADY_IN_USE'
);

require(
!hasRole(DISTRIBUTOR_ROLE, msg.sender) && !hasRole(DISTRIBUTOR_ROLE, newAddress),
'TokenDistro::changeAddress: DISTRIBUTOR_ROLE_NOT_A_VALID_ADDRESS'
);

balances[newAddress].allocatedTokens = balances[msg.sender].allocatedTokens;
balances[msg.sender].allocatedTokens = 0;

balances[newAddress].claimed = balances[msg.sender].claimed;
balances[msg.sender].claimed = 0;

emit ChangeAddress(msg.sender, newAddress);
_transferAllocation(msg.sender, newAddress);
}

/**
Expand Down Expand Up @@ -284,29 +278,13 @@ contract TokenDistro is Initializable, IDistro, AccessControlEnumerableUpgradeab
*
* Emits a {ChangeAddress} event.
*
* Formerly called cancelAllocation, this is an admin only function and should only be called manually
*/
function cancelAllocation(address prevRecipient, address newRecipient) external override {
require(cancelable, 'TokenDistro::cancelAllocation: NOT_CANCELABLE');

require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), 'TokenDistro::cancelAllocation: ONLY_ADMIN_ROLE');

require(
balances[newRecipient].allocatedTokens == 0 && balances[newRecipient].claimed == 0,
'TokenDistro::cancelAllocation: ADDRESS_ALREADY_IN_USE'
);

require(
!hasRole(DISTRIBUTOR_ROLE, prevRecipient) && !hasRole(DISTRIBUTOR_ROLE, newRecipient),
'TokenDistro::cancelAllocation: DISTRIBUTOR_ROLE_NOT_A_VALID_ADDRESS'
);

balances[newRecipient].allocatedTokens = balances[prevRecipient].allocatedTokens;
balances[prevRecipient].allocatedTokens = 0;
function transferAllocation(address prevRecipient, address newRecipient) external override {
require(cancelable, 'TokenDistro::transferAllocation: NOT_CANCELABLE');

balances[newRecipient].claimed = balances[prevRecipient].claimed;
balances[prevRecipient].claimed = 0;

emit ChangeAddress(prevRecipient, newRecipient);
require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), 'TokenDistro::transferAllocation: ONLY_ADMIN_ROLE');
_transferAllocation(prevRecipient, newRecipient);
}

/**
Expand Down Expand Up @@ -339,4 +317,23 @@ contract TokenDistro is Initializable, IDistro, AccessControlEnumerableUpgradeab

emit DurationChanged(newDuration);
}

function _transferAllocation(address prevRecipient, address newRecipient) internal {
require(
balances[prevRecipient].allocatedTokens > 0, 'TokenDistro::transferAllocation: NO_ALLOCATION_TO_TRANSFER'
);
require(
!hasRole(DISTRIBUTOR_ROLE, prevRecipient) && !hasRole(DISTRIBUTOR_ROLE, newRecipient),
'TokenDistro::transferAllocation: DISTRIBUTOR_ROLE_NOT_A_VALID_ADDRESS'
);
// balance adds instead of overwrites
balances[newRecipient].allocatedTokens =
balances[prevRecipient].allocatedTokens + balances[newRecipient].allocatedTokens;
balances[prevRecipient].allocatedTokens = 0;

balances[newRecipient].claimed = balances[prevRecipient].claimed + balances[newRecipient].claimed;
balances[prevRecipient].claimed = 0;

emit ChangeAddress(prevRecipient, newRecipient);
}
}
6 changes: 4 additions & 2 deletions contracts/interfaces/IDistro.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity =0.8.10;
pragma solidity ^0.8.10;

Check warning

Code scanning / Slither

Incorrect versions of Solidity Warning

Version constraint ^0.8.10 contains known severe issues (https://solidity.readthedocs.io/en/latest/bugs.html)
- VerbatimInvalidDeduplication
- FullInlinerNonExpressionSplitArgumentEvaluationOrder
- MissingSideEffectsOnSelectorAccess
- AbiReencodingHeadOverflowWithStaticArrayCleanup
- DirtyBytesArrayToStorage
- DataLocationChangeInInternalOverride
- NestedCalldataArrayAbiReencodingSizeValidation.
It is used by:
- ^0.8.10

interface IDistro {
/**
Expand Down Expand Up @@ -98,5 +98,7 @@
*/
function claimableNow(address recipient) external view returns (uint256);

function cancelAllocation(address prevRecipient, address newRecipient) external;
function transferAllocation(address prevRecipient, address newRecipient) external;

function sendPraiseRewards(address[] memory recipients, uint256[] memory amounts) external;
}
2 changes: 1 addition & 1 deletion contracts/tokens/UniswapV3RewardToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.10;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
import '../Interfaces/IDistro.sol';
import '../interfaces/IDistro.sol';

contract UniswapV3RewardToken is IERC20, OwnableUpgradeable {
uint256 public initialBalance;
Expand Down
2 changes: 1 addition & 1 deletion script/deployRelayerOptimism.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract deployRelayer is Script {
tokenDistro.grantRole(keccak256('DISTRIBUTOR_ROLE'), address(givbacksRelayer));
tokenDistro.assign(address(givbacksRelayer), 2500000 ether);
tokenDistro.revokeRole(keccak256('DISTRIBUTOR_ROLE'), address(batcherApp));
tokenDistro.cancelAllocation(address(batcherApp), 0x0000000000000000000000000000000000000000);
tokenDistro.transferAllocation(address(batcherApp), 0x0000000000000000000000000000000000000000);

console.log('proxy admin', address(givbacksRelayerProxyAdmin));
console.log('givbacks relayer', address(givbacksRelayer));
Expand Down
Loading
Loading