-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
2d09249
make modifications for transferAllocation function
divine-comedian 059ce20
forge fmt
divine-comedian 4d74c18
Merge branch 'develop' into modify-allocation-functions
aminlatifi afa189a
fix typo in import
divine-comedian e15fece
add internal transferAllocation function, remove safemath
divine-comedian b7f27a8
add more checks from review
divine-comedian 4162390
forge fmt
divine-comedian 321d2c6
add comment to tranferAllocation
divine-comedian a98fd5a
test fix
divine-comedian 9ce32b6
explcitly set node-version
divine-comedian 61908de
syntax
divine-comedian 51d4195
specify node 20
divine-comedian 3e4dafc
Update slither.yml
divine-comedian 8b0058a
Update slither.yml
divine-comedian 7933fdc
Update slither.yml
divine-comedian abcd659
Update slither.yml
divine-comedian 1c30d00
Update slither.yml
divine-comedian 4ada5ab
add sendPraise to interface, forge fmt, remove some checks
divine-comedian ef0e40c
add sendPraise to interface, forge fmt, remove some checks
divine-comedian e1be749
Merge branch 'modify-allocation-functions' of github.com:Giveth/givpo…
divine-comedian 5c99dd7
revert tokendistro changes
divine-comedian 5e9c632
remove checks from Griff's feedback
divine-comedian 9b41730
add latest version of token distro
divine-comedian 021dc01
forge fmt, missing override on praise
divine-comedian 1fcb74c
Moved changes to the same TokenDistro contract
aminlatifi ee655a7
Reverted slither changes
aminlatifi e81bd24
Upgrade dependencies
aminlatifi 2b377b5
returned slither action back
aminlatifi 2a4e88e
Move to new slither config
aminlatifi 530b742
Upgraded slither action
aminlatifi 64b9f23
Modified sliter action
aminlatifi 579b40d
Modified slither action
aminlatifi 61a1315
Merge branch 'develop' into modify-allocation-functions
aminlatifi 6e5b328
Removed a repetitive function definition
aminlatifi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,270 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.6; | ||
|
||
import '@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; | ||
import '@openzeppelin/contracts/utils/math/SafeMath.sol'; | ||
import '@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol'; | ||
import '@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol'; | ||
import 'forge-std/Test.sol'; | ||
import 'forge-std/console.sol'; | ||
import '../contracts/TokenDistro.sol'; | ||
|
||
contract TokenDistroTransferAllocation is Test { | ||
using SafeERC20Upgradeable for IERC20Upgradeable; | ||
using SafeMath for uint256; | ||
|
||
ProxyAdmin proxyAdmin; | ||
IERC20Upgradeable givToken; | ||
address givethMultisig; | ||
address distributor; | ||
address firstRecipient; | ||
address secondRecipient; | ||
address thirdRecipient; | ||
|
||
// deploy the token distro | ||
TransparentUpgradeableProxy tokenDistroProxy; | ||
IDistro tokenDistroInterface; | ||
TokenDistro tokenDistro; | ||
TokenDistro tokenDistroImplementation; | ||
uint256 assignedAmount = 10000000000000000000000000; | ||
uint256 forkBlock = 22501098; | ||
|
||
constructor() { | ||
uint256 forkId = vm.createFork('https://rpc.ankr.com/gnosis', forkBlock); //https://xdai-archive.blockscout.com/ | ||
vm.selectFork(forkId); | ||
proxyAdmin = ProxyAdmin(address(0x076C250700D210e6cf8A27D1EB1Fd754FB487986)); | ||
tokenDistro = TokenDistro(address(0xc0dbDcA66a0636236fAbe1B3C16B1bD4C84bB1E1)); | ||
tokenDistroProxy = TransparentUpgradeableProxy(payable(address(0xc0dbDcA66a0636236fAbe1B3C16B1bD4C84bB1E1))); | ||
givethMultisig = 0x4D9339dd97db55e3B9bCBE65dE39fF9c04d1C2cd; | ||
givToken = IERC20Upgradeable(address(0x4f4F9b8D5B4d0Dc10506e5551B0513B61fD59e75)); | ||
distributor = address(5); | ||
firstRecipient = address(6); | ||
secondRecipient = address(7); | ||
thirdRecipient = address(8); | ||
} | ||
|
||
function setUp() public { | ||
vm.startPrank(givethMultisig); | ||
tokenDistroImplementation = new TokenDistro(); | ||
proxyAdmin.upgrade(tokenDistroProxy, address(tokenDistroImplementation)); | ||
tokenDistro.grantRole(keccak256('DISTRIBUTOR_ROLE'), distributor); | ||
tokenDistro.assign(distributor, assignedAmount); | ||
vm.stopPrank(); | ||
|
||
vm.label(address(tokenDistro), 'tokenDistroContract'); | ||
vm.label(address(tokenDistroImplementation), 'tokenDistroImplementation'); | ||
vm.label(address(tokenDistroProxy), 'tokenDistroProxy'); | ||
vm.label(address(givToken), 'givToken'); | ||
vm.label(address(givethMultisig), 'givethMultisig'); | ||
vm.label(address(distributor), 'distributor'); | ||
vm.label(address(firstRecipient), 'firstRecipient'); | ||
vm.label(address(secondRecipient), 'secondRecipient'); | ||
vm.label(address(thirdRecipient), 'thirdRecipient'); | ||
} | ||
|
||
function testTransferAllocation(uint256 amount1, uint256 amount2, uint256 amount3) public { | ||
// bound the amounts to be between 1 and 1/3 of the assigned amount so it cannot go over the assigned amount | ||
amount1 = bound(amount1, 1, assignedAmount.div(3)); | ||
amount2 = bound(amount2, 1, assignedAmount.div(3)); | ||
amount3 = bound(amount3, 1, assignedAmount.div(3)); | ||
// setup the distribution arrays for allocation | ||
address[] memory recipients = new address[](3); | ||
recipients[0] = firstRecipient; | ||
recipients[1] = secondRecipient; | ||
recipients[2] = thirdRecipient; | ||
|
||
uint256[] memory amounts = new uint256[](3); | ||
amounts[0] = amount1; | ||
amounts[1] = amount2; | ||
amounts[2] = amount3; | ||
|
||
// give some starting allocations to the recipients | ||
vm.prank(distributor); | ||
tokenDistro.allocateMany(recipients, amounts); | ||
|
||
// save balance values | ||
(uint256 firstRecipientAllocatedTokens,) = tokenDistro.balances(firstRecipient); | ||
(uint256 secondRecipientAllocatedTokens,) = tokenDistro.balances(secondRecipient); | ||
// make first transfer from first recipient to second recipient | ||
vm.prank(givethMultisig); | ||
tokenDistro.transferAllocation(firstRecipient, secondRecipient); | ||
|
||
// save balance values after first transfer | ||
(uint256 secondRecipientAllocatedTokensAfterTransfer,) = tokenDistro.balances(secondRecipient); | ||
(uint256 firstRecipientAllocatedTokensAfterTransfer,) = tokenDistro.balances(firstRecipient); | ||
// log some stuff | ||
console.log('secondRecipientAllocatedTokensAfterTransfer: ', secondRecipientAllocatedTokensAfterTransfer); | ||
console.log('secondRecipientAllocatedTokens: ', secondRecipientAllocatedTokens); | ||
console.log('firstRecipientAllocatedTokensAfterTransfer: ', firstRecipientAllocatedTokensAfterTransfer); | ||
console.log('firstRecipientAllocatedTokens: ', firstRecipientAllocatedTokens); | ||
// assertions | ||
assertEq( | ||
secondRecipientAllocatedTokensAfterTransfer, | ||
(firstRecipientAllocatedTokens.add(secondRecipientAllocatedTokens)) | ||
); | ||
assertEq(firstRecipientAllocatedTokensAfterTransfer, 0); | ||
|
||
// do second transfer from second recip to third recip | ||
vm.prank(givethMultisig); | ||
tokenDistro.transferAllocation(secondRecipient, thirdRecipient); | ||
|
||
// save balance values after second transfer | ||
(uint256 thirdRecipientAllocatedTokensAfterTransfer,) = tokenDistro.balances(thirdRecipient); | ||
(uint256 secondRecipientAllocatedTokensAfterSecondTransfer,) = tokenDistro.balances(secondRecipient); | ||
// expected amount should be the sum of all three amounts | ||
uint256 expectedAmount = amount1.add(amount2.add(amount3)); | ||
// log some stuff | ||
console.log('thirdRecipientAllocatedTokensAfterTransfer: ', thirdRecipientAllocatedTokensAfterTransfer); | ||
console.log('expectedAmount: ', expectedAmount); | ||
// assertions | ||
assertEq(thirdRecipientAllocatedTokensAfterTransfer, expectedAmount); | ||
assertEq(secondRecipientAllocatedTokensAfterSecondTransfer, 0); | ||
} | ||
|
||
function testTransferAllocationWithClaim(uint256 amount1, uint256 amount2) public { | ||
amount1 = bound(amount1, 10, (assignedAmount - 1).div(2)); | ||
amount2 = bound(amount2, 10, assignedAmount.div(2)); | ||
|
||
address[] memory recipients = new address[](2); | ||
recipients[0] = firstRecipient; | ||
recipients[1] = secondRecipient; | ||
|
||
uint256[] memory amounts = new uint256[](2); | ||
amounts[0] = amount1; | ||
amounts[1] = amount2; | ||
|
||
vm.prank(distributor); | ||
tokenDistro.allocateMany(recipients, amounts); | ||
|
||
// skip ahead some time and then claim tokens | ||
skip(14 days); | ||
console.log('claimable for first recipient', tokenDistro.claimableNow(firstRecipient)); | ||
console.log('claimable for second recipient', tokenDistro.claimableNow(secondRecipient)); | ||
|
||
vm.prank(firstRecipient); | ||
tokenDistro.claim(); | ||
vm.prank(secondRecipient); | ||
tokenDistro.claim(); | ||
|
||
// save balance values | ||
(, uint256 secondRecipientClaimedTokens) = tokenDistro.balances(secondRecipient); | ||
(, uint256 firstRecipientClaimedTokens) = tokenDistro.balances(firstRecipient); | ||
// transfer allocation to second recipient | ||
vm.prank(givethMultisig); | ||
tokenDistro.transferAllocation(firstRecipient, secondRecipient); | ||
// check values of second recipient after transfer | ||
(uint256 secondAllocatedAfterTransfer, uint256 secondClaimedAfterTransfer) = | ||
tokenDistro.balances(secondRecipient); | ||
(uint256 firstAllocatedAfterTransfer, uint256 firstClaimedAfterTransfer) = tokenDistro.balances(firstRecipient); | ||
// assertions | ||
assertEq(secondAllocatedAfterTransfer, (amount1.add(amount2))); | ||
assertEq(secondClaimedAfterTransfer, (secondRecipientClaimedTokens.add(firstRecipientClaimedTokens))); | ||
assertEq(firstAllocatedAfterTransfer, 0); | ||
assertEq(firstClaimedAfterTransfer, 0); | ||
} | ||
|
||
function testChangeAddress(uint256 amount1, uint256 amount2, uint256 amount3) public { | ||
// bound the amounts to be between 1 and 1/3 of the assigned amount so it cannot go over the assigned amount | ||
amount1 = bound(amount1, 1, assignedAmount.div(3)); | ||
amount2 = bound(amount2, 1, assignedAmount.div(3)); | ||
amount3 = bound(amount3, 1, assignedAmount.div(3)); | ||
// setup the distribution arrays for allocation | ||
address[] memory recipients = new address[](3); | ||
recipients[0] = firstRecipient; | ||
recipients[1] = secondRecipient; | ||
recipients[2] = thirdRecipient; | ||
|
||
uint256[] memory amounts = new uint256[](3); | ||
amounts[0] = amount1; | ||
amounts[1] = amount2; | ||
amounts[2] = amount3; | ||
|
||
// give some starting allocations to the recipients | ||
vm.prank(distributor); | ||
tokenDistro.allocateMany(recipients, amounts); | ||
|
||
// save balance values | ||
(uint256 firstRecipientAllocatedTokens,) = tokenDistro.balances(firstRecipient); | ||
(uint256 secondRecipientAllocatedTokens,) = tokenDistro.balances(secondRecipient); | ||
// make first transfer from first recipient to second recipient | ||
vm.prank(firstRecipient); | ||
tokenDistro.changeAddress(secondRecipient); | ||
|
||
// save balance values after first transfer | ||
(uint256 secondRecipientAllocatedTokensAfterTransfer,) = tokenDistro.balances(secondRecipient); | ||
(uint256 firstRecipientAllocatedTokensAfterTransfer,) = tokenDistro.balances(firstRecipient); | ||
// log some stuff | ||
console.log('secondRecipientAllocatedTokensAfterTransfer: ', secondRecipientAllocatedTokensAfterTransfer); | ||
console.log('secondRecipientAllocatedTokens: ', secondRecipientAllocatedTokens); | ||
console.log('firstRecipientAllocatedTokensAfterTransfer: ', firstRecipientAllocatedTokensAfterTransfer); | ||
console.log('firstRecipientAllocatedTokens: ', firstRecipientAllocatedTokens); | ||
// assertions | ||
assertEq( | ||
secondRecipientAllocatedTokensAfterTransfer, | ||
(firstRecipientAllocatedTokens.add(secondRecipientAllocatedTokens)) | ||
); | ||
assertEq(firstRecipientAllocatedTokensAfterTransfer, 0); | ||
|
||
// do second transfer from second recip to third recip | ||
vm.prank(secondRecipient); | ||
tokenDistro.changeAddress(thirdRecipient); | ||
|
||
// save balance values after second transfer | ||
(uint256 thirdRecipientAllocatedTokensAfterTransfer,) = tokenDistro.balances(thirdRecipient); | ||
(uint256 secondRecipientAllocatedTokensAfterSecondTransfer,) = tokenDistro.balances(secondRecipient); | ||
// expected amount should be the sum of all three amounts | ||
uint256 expectedAmount = amount1.add(amount2.add(amount3)); | ||
// log some stuff | ||
console.log('thirdRecipientAllocatedTokensAfterTransfer: ', thirdRecipientAllocatedTokensAfterTransfer); | ||
console.log('expectedAmount: ', expectedAmount); | ||
// assertions | ||
assertEq(thirdRecipientAllocatedTokensAfterTransfer, expectedAmount); | ||
assertEq(secondRecipientAllocatedTokensAfterSecondTransfer, 0); | ||
} | ||
|
||
function testChangeAddressWithClaim(uint256 amount1, uint256 amount2) public { | ||
/// @aminlatifi for some reason this does not want to work with the min bound as 1 - throws no tokens to claim error | ||
amount1 = bound(amount1, 10, (assignedAmount - 1).div(2)); | ||
amount2 = bound(amount2, 10, assignedAmount.div(2)); | ||
|
||
address[] memory recipients = new address[](2); | ||
recipients[0] = firstRecipient; | ||
recipients[1] = secondRecipient; | ||
|
||
uint256[] memory amounts = new uint256[](2); | ||
amounts[0] = amount1; | ||
amounts[1] = amount2; | ||
|
||
vm.prank(distributor); | ||
tokenDistro.allocateMany(recipients, amounts); | ||
|
||
// skip ahead some time and then claim tokens | ||
skip(14 days); | ||
console.log('claimable for first recipient', tokenDistro.claimableNow(firstRecipient)); | ||
console.log('claimable for second recipient', tokenDistro.claimableNow(secondRecipient)); | ||
|
||
vm.prank(firstRecipient); | ||
tokenDistro.claim(); | ||
vm.prank(secondRecipient); | ||
tokenDistro.claim(); | ||
|
||
// save balance values | ||
(, uint256 secondRecipientClaimedTokens) = tokenDistro.balances(secondRecipient); | ||
(, uint256 firstRecipientClaimedTokens) = tokenDistro.balances(firstRecipient); | ||
// transfer allocation to second recipient | ||
vm.prank(firstRecipient); | ||
tokenDistro.changeAddress(secondRecipient); | ||
// check values of second recipient after transfer | ||
(uint256 secondAllocatedAfterTransfer, uint256 secondClaimedAfterTransfer) = | ||
tokenDistro.balances(secondRecipient); | ||
(uint256 firstAllocatedAfterTransfer, uint256 firstClaimedAfterTransfer) = tokenDistro.balances(firstRecipient); | ||
// assertions | ||
assertEq(secondAllocatedAfterTransfer, (amount1.add(amount2))); | ||
assertEq(secondClaimedAfterTransfer, (secondRecipientClaimedTokens.add(firstRecipientClaimedTokens))); | ||
assertEq(firstAllocatedAfterTransfer, 0); | ||
assertEq(firstClaimedAfterTransfer, 0); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / Slither
Incorrect versions of Solidity Warning