diff --git a/README.md b/README.md index 135a7ec..4df9b8a 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,12 @@ - [x] Different staking pool implemented customStake/customUnstake - [x] Implemented ability for admin to change custom pool APY value * +- [x] Implemented custom reward Pool redistribution +* - [ ] Add frontend for custom pool -- [ ] Implement different APY Pool reward redistribution - [ ] Add loader, indicator - [ ] Split components in to smaller - [ ] Validate contracts -- [ ] Add different Staking pools [doing] - [ ] Add clear running description @@ -72,50 +72,58 @@ mocha testing output ``` Contract: TokenStaking TestToken deployment - ✓ token deployed and has a name (209ms) + ✓ token deployed and has a name (246ms) TokenStaking deployment - ✓ staking contract deployed and has a name (83ms) - ✓ checking default APY value (109ms) - ✓ checking custom APY value (146ms) - ✓ staking contract has 500k TestTokens tokens inside (105ms) + ✓ staking contract deployed and has a name (160ms) + ✓ checking default APY value (179ms) + ✓ checking custom APY value (128ms) + ✓ staking contract has 500k TestTokens tokens inside (176ms) TokenStaking stakeTokens function - ✓ users balance is correct before staking (139ms) - ✓ checking total staked before any stakes (106ms) - ✓ aproving tokens, staking tokens, checking balance (1034ms) - ✓ checking contract balance after staking (84ms) - ✓ checking user balance inside contract (109ms) - ✓ checking total staked (81ms) - ✓ testing if user is staking at the moment (153ms) - ✓ testing if user has staked (99ms) + ✓ users balance is correct before staking (126ms) + ✓ checking total staked before any stakes (126ms) + ✓ aproving tokens, staking tokens, checking balance (1259ms) + ✓ checking contract balance after staking (156ms) + ✓ checking user balance inside contract (131ms) + ✓ checking total staked (136ms) + ✓ testing if user is staking at the moment (148ms) + ✓ testing if user has staked (145ms) TokenStaking redistributeRewards function - ✓ checking who can do redistribution (1259ms) - ✓ checking TokenStaking balance (136ms) - ✓ checking user balance (95ms) + ✓ checking who can do redistribution (1059ms) + ✓ checking TokenStaking balance (105ms) + ✓ checking user balance (130ms) TokenStaking unstakeTokens function - ✓ unstaking and checking users balance after unstake (620ms) - ✓ checking total staked (174ms) + ✓ unstaking and checking users balance after unstake (468ms) + ✓ checking total staked (132ms) TokenStaking [custom] staking/unstaking functions - ✓ checking total custom staked before any stakes (189ms) - ✓ checking usrs balance before staking (128ms) - ✓ aproving tokens, staking tokens, checking balance (945ms) - ✓ checking custom total staked (143ms) - ✓ testing if user is staking at custom staking at the moment (124ms) - ✓ testing if user has staked at custom staking (157ms) - ✓ unstaking from custom staking and checking users balance (683ms) + ✓ checking total custom staked before any stakes (132ms) + ✓ checking usrs balance before staking (165ms) + ✓ aproving tokens, staking tokens, checking balance (1131ms) + ✓ checking custom total staked (125ms) + ✓ testing if user is staking at custom staking at the moment (147ms) + ✓ testing if user has staked at custom staking (107ms) + ✓ unstaking from custom staking and checking users balance (535ms) Claim Tst - ✓ trying to obtain 1000 test token (373ms) + ✓ trying to obtain 1000 test token (395ms) Change custom APY value - ✓ checking who can change APY (1069ms) - ✓ checking new custom APY value (172ms) + ✓ checking who can change APY (1115ms) + ✓ checking new custom APY value (146ms) + Testing custom APY reward redistribution + ✓ staking at customStaking (1299ms) + ✓ redistributing rewards, checking who can redistribute (733ms) + ✓ checking user balance after custom APY rewards (111ms) ``` for private ethereum test network make sure Ganache is running on HTTP://127.0.0.1:7545 -Smart Contract Address on Test Net -Ropsten: 0xABa3314745b3eBCF91Eb4a61f695fc55B81119eF -Rinkeby: 0xB18D4a5D7bc8450A957f7AD1675D5e606d4482B0 +TokenStaking Smart Contract Address on Test Net +Ropsten: 0x0Fab2A018bB44DD2a6Ef7C55F057Dd9d9eC1B19F +Rinkeby: 0xAf9352B33E9B08A86dD04fcD8533DbC75BD2c8d1 + +TestToken Contract Address on Test Net +Ropsten: 0x0190f80487179053eb85451454541644AbAf4048 +Rinkeby: 0xb54039DAC3C4ADdAC082e86a6e9C290E80af9488 -Token Contract Address on Test Net -Ropsten: 0xC8B88a647b0c3D2CCce7bD561C8285c1FaA79b15 -Rinkeby: 0xEc8E737d460B5DbD62E9B3062b6e7E472FCe2B06 +Current Admin on Test Net +Ropsten: 0x3349ca399168dF1c0df96a49410F5F9940241AbC +Rinkeby: 0x3349ca399168dF1c0df96a49410F5F9940241AbC diff --git a/scripts/customRewards.js b/scripts/customRewards.js new file mode 100644 index 0000000..af2c80c --- /dev/null +++ b/scripts/customRewards.js @@ -0,0 +1,10 @@ +const TokenStaking = artifacts.require('TokenStaking'); + +module.exports = async function(callback) { + let tokenStaking = await TokenStaking.deployed(); + await tokenStaking.customRewards(); + console.log('--- Daily [Custom] rewards have been redistributed ---'); + callback(); +}; + +//to run script - truffle exec scripts/customRewards.js \ No newline at end of file diff --git a/src/abis/Migrations.json b/src/abis/Migrations.json index c7b57ce..f881ffe 100644 --- a/src/abis/Migrations.json +++ b/src/abis/Migrations.json @@ -202,7 +202,7 @@ "name": "msg", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 258, + "referencedDeclaration": 71, "src": "158:3:0", "typeDescriptions": { "typeIdentifier": "t_magic_message", @@ -286,7 +286,7 @@ "name": "msg", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 258, + "referencedDeclaration": 71, "src": "209:3:0", "typeDescriptions": { "typeIdentifier": "t_magic_message", @@ -725,652 +725,746 @@ "src": "0:515:0" }, "legacyAST": { - "absolutePath": "/mnt/e/APP DEVELOPEMENT/APP DEV NEW/BLOCKCHAIN/Token Staking dApp/src/contracts/Migrations.sol", - "exportedSymbols": { - "Migrations": [ - 56 - ] + "attributes": { + "absolutePath": "/mnt/e/APP DEVELOPEMENT/APP DEV NEW/BLOCKCHAIN/Token Staking dApp/src/contracts/Migrations.sol", + "exportedSymbols": { + "Migrations": [ + 56 + ] + } }, - "id": 57, - "nodeType": "SourceUnit", - "nodes": [ + "children": [ { + "attributes": { + "literals": [ + "solidity", + ">=", + "0.4", + ".21", + "<", + "0.6", + ".0" + ] + }, "id": 1, - "literals": [ - "solidity", - ">=", - "0.4", - ".21", - "<", - "0.6", - ".0" - ], - "nodeType": "PragmaDirective", + "name": "PragmaDirective", "src": "0:32:0" }, { - "baseContracts": [], - "contractDependencies": [], - "contractKind": "contract", - "documentation": null, - "fullyImplemented": true, - "id": 56, - "linearizedBaseContracts": [ - 56 - ], - "name": "Migrations", - "nodeType": "ContractDefinition", - "nodes": [ + "attributes": { + "baseContracts": [ + null + ], + "contractDependencies": [ + null + ], + "contractKind": "contract", + "documentation": null, + "fullyImplemented": true, + "linearizedBaseContracts": [ + 56 + ], + "name": "Migrations", + "scope": 57 + }, + "children": [ { - "constant": false, - "id": 3, - "name": "owner", - "nodeType": "VariableDeclaration", - "scope": 56, - "src": "58:20:0", - "stateVariable": true, - "storageLocation": "default", - "typeDescriptions": { - "typeIdentifier": "t_address", - "typeString": "address" + "attributes": { + "constant": false, + "name": "owner", + "scope": 56, + "stateVariable": true, + "storageLocation": "default", + "type": "address", + "value": null, + "visibility": "public" }, - "typeName": { - "id": 2, - "name": "address", - "nodeType": "ElementaryTypeName", - "src": "58:7:0", - "stateMutability": "nonpayable", - "typeDescriptions": { - "typeIdentifier": "t_address", - "typeString": "address" + "children": [ + { + "attributes": { + "name": "address", + "stateMutability": "nonpayable", + "type": "address" + }, + "id": 2, + "name": "ElementaryTypeName", + "src": "58:7:0" } - }, - "value": null, - "visibility": "public" + ], + "id": 3, + "name": "VariableDeclaration", + "src": "58:20:0" }, { - "constant": false, - "id": 5, - "name": "last_completed_migration", - "nodeType": "VariableDeclaration", - "scope": 56, - "src": "82:36:0", - "stateVariable": true, - "storageLocation": "default", - "typeDescriptions": { - "typeIdentifier": "t_uint256", - "typeString": "uint256" + "attributes": { + "constant": false, + "name": "last_completed_migration", + "scope": 56, + "stateVariable": true, + "storageLocation": "default", + "type": "uint256", + "value": null, + "visibility": "public" }, - "typeName": { - "id": 4, - "name": "uint", - "nodeType": "ElementaryTypeName", - "src": "82:4:0", - "typeDescriptions": { - "typeIdentifier": "t_uint256", - "typeString": "uint256" + "children": [ + { + "attributes": { + "name": "uint", + "type": "uint256" + }, + "id": 4, + "name": "ElementaryTypeName", + "src": "82:4:0" } - }, - "value": null, - "visibility": "public" + ], + "id": 5, + "name": "VariableDeclaration", + "src": "82:36:0" }, { - "body": { - "id": 13, - "nodeType": "Block", - "src": "144:29:0", - "statements": [ - { - "expression": { - "argumentTypes": null, - "id": 11, - "isConstant": false, - "isLValue": false, - "isPure": false, - "lValueRequested": false, - "leftHandSide": { - "argumentTypes": null, - "id": 8, - "name": "owner", - "nodeType": "Identifier", - "overloadedDeclarations": [], - "referencedDeclaration": 3, - "src": "150:5:0", - "typeDescriptions": { - "typeIdentifier": "t_address", - "typeString": "address" - } - }, - "nodeType": "Assignment", - "operator": "=", - "rightHandSide": { - "argumentTypes": null, - "expression": { - "argumentTypes": null, - "id": 9, - "name": "msg", - "nodeType": "Identifier", - "overloadedDeclarations": [], - "referencedDeclaration": 258, - "src": "158:3:0", - "typeDescriptions": { - "typeIdentifier": "t_magic_message", - "typeString": "msg" - } - }, - "id": 10, - "isConstant": false, - "isLValue": false, - "isPure": false, - "lValueRequested": false, - "memberName": "sender", - "nodeType": "MemberAccess", - "referencedDeclaration": null, - "src": "158:10:0", - "typeDescriptions": { - "typeIdentifier": "t_address_payable", - "typeString": "address payable" - } - }, - "src": "150:18:0", - "typeDescriptions": { - "typeIdentifier": "t_address", - "typeString": "address" - } - }, - "id": 12, - "nodeType": "ExpressionStatement", - "src": "150:18:0" - } - ] - }, - "documentation": null, - "id": 14, - "implemented": true, - "kind": "constructor", - "modifiers": [], - "name": "", - "nodeType": "FunctionDefinition", - "parameters": { - "id": 6, - "nodeType": "ParameterList", - "parameters": [], - "src": "134:2:0" - }, - "returnParameters": { - "id": 7, - "nodeType": "ParameterList", - "parameters": [], - "src": "144:0:0" + "attributes": { + "documentation": null, + "implemented": true, + "isConstructor": true, + "kind": "constructor", + "modifiers": [ + null + ], + "name": "", + "scope": 56, + "stateMutability": "nonpayable", + "superFunction": null, + "visibility": "public" }, - "scope": 56, - "src": "123:50:0", - "stateMutability": "nonpayable", - "superFunction": null, - "visibility": "public" - }, - { - "body": { - "id": 22, - "nodeType": "Block", - "src": "199:37:0", - "statements": [ - { - "condition": { - "argumentTypes": null, - "commonType": { - "typeIdentifier": "t_address", - "typeString": "address" - }, - "id": 19, - "isConstant": false, - "isLValue": false, - "isPure": false, - "lValueRequested": false, - "leftExpression": { - "argumentTypes": null, - "expression": { - "argumentTypes": null, - "id": 16, - "name": "msg", - "nodeType": "Identifier", - "overloadedDeclarations": [], - "referencedDeclaration": 258, - "src": "209:3:0", - "typeDescriptions": { - "typeIdentifier": "t_magic_message", - "typeString": "msg" - } - }, - "id": 17, - "isConstant": false, - "isLValue": false, - "isPure": false, - "lValueRequested": false, - "memberName": "sender", - "nodeType": "MemberAccess", - "referencedDeclaration": null, - "src": "209:10:0", - "typeDescriptions": { - "typeIdentifier": "t_address_payable", - "typeString": "address payable" - } - }, - "nodeType": "BinaryOperation", - "operator": "==", - "rightExpression": { - "argumentTypes": null, - "id": 18, - "name": "owner", - "nodeType": "Identifier", - "overloadedDeclarations": [], - "referencedDeclaration": 3, - "src": "223:5:0", - "typeDescriptions": { - "typeIdentifier": "t_address", - "typeString": "address" + "children": [ + { + "attributes": { + "parameters": [ + null + ] + }, + "children": [], + "id": 6, + "name": "ParameterList", + "src": "134:2:0" + }, + { + "attributes": { + "parameters": [ + null + ] + }, + "children": [], + "id": 7, + "name": "ParameterList", + "src": "144:0:0" + }, + { + "children": [ + { + "children": [ + { + "attributes": { + "argumentTypes": null, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "operator": "=", + "type": "address" + }, + "children": [ + { + "attributes": { + "argumentTypes": null, + "overloadedDeclarations": [ + null + ], + "referencedDeclaration": 3, + "type": "address", + "value": "owner" + }, + "id": 8, + "name": "Identifier", + "src": "150:5:0" + }, + { + "attributes": { + "argumentTypes": null, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "member_name": "sender", + "referencedDeclaration": null, + "type": "address payable" + }, + "children": [ + { + "attributes": { + "argumentTypes": null, + "overloadedDeclarations": [ + null + ], + "referencedDeclaration": 71, + "type": "msg", + "value": "msg" + }, + "id": 9, + "name": "Identifier", + "src": "158:3:0" + } + ], + "id": 10, + "name": "MemberAccess", + "src": "158:10:0" + } + ], + "id": 11, + "name": "Assignment", + "src": "150:18:0" } - }, - "src": "209:19:0", - "typeDescriptions": { - "typeIdentifier": "t_bool", - "typeString": "bool" - } - }, - "falseBody": null, - "id": 21, - "nodeType": "IfStatement", - "src": "205:26:0", - "trueBody": { - "id": 20, - "nodeType": "PlaceholderStatement", - "src": "230:1:0" + ], + "id": 12, + "name": "ExpressionStatement", + "src": "150:18:0" } - } - ] - }, - "documentation": null, - "id": 23, - "name": "restricted", - "nodeType": "ModifierDefinition", - "parameters": { - "id": 15, - "nodeType": "ParameterList", - "parameters": [], - "src": "196:2:0" - }, - "src": "177:59:0", - "visibility": "internal" + ], + "id": 13, + "name": "Block", + "src": "144:29:0" + } + ], + "id": 14, + "name": "FunctionDefinition", + "src": "123:50:0" }, { - "body": { - "id": 34, - "nodeType": "Block", - "src": "296:47:0", - "statements": [ - { - "expression": { - "argumentTypes": null, - "id": 32, - "isConstant": false, - "isLValue": false, - "isPure": false, - "lValueRequested": false, - "leftHandSide": { - "argumentTypes": null, - "id": 30, - "name": "last_completed_migration", - "nodeType": "Identifier", - "overloadedDeclarations": [], - "referencedDeclaration": 5, - "src": "302:24:0", - "typeDescriptions": { - "typeIdentifier": "t_uint256", - "typeString": "uint256" - } - }, - "nodeType": "Assignment", - "operator": "=", - "rightHandSide": { - "argumentTypes": null, - "id": 31, - "name": "completed", - "nodeType": "Identifier", - "overloadedDeclarations": [], - "referencedDeclaration": 25, - "src": "329:9:0", - "typeDescriptions": { - "typeIdentifier": "t_uint256", - "typeString": "uint256" - } - }, - "src": "302:36:0", - "typeDescriptions": { - "typeIdentifier": "t_uint256", - "typeString": "uint256" - } - }, - "id": 33, - "nodeType": "ExpressionStatement", - "src": "302:36:0" - } - ] + "attributes": { + "documentation": null, + "name": "restricted", + "visibility": "internal" }, - "documentation": null, - "id": 35, - "implemented": true, - "kind": "function", - "modifiers": [ + "children": [ { - "arguments": null, - "id": 28, - "modifierName": { - "argumentTypes": null, - "id": 27, - "name": "restricted", - "nodeType": "Identifier", - "overloadedDeclarations": [], - "referencedDeclaration": 23, - "src": "285:10:0", - "typeDescriptions": { - "typeIdentifier": "t_modifier$__$", - "typeString": "modifier ()" - } + "attributes": { + "parameters": [ + null + ] }, - "nodeType": "ModifierInvocation", - "src": "285:10:0" + "children": [], + "id": 15, + "name": "ParameterList", + "src": "196:2:0" + }, + { + "children": [ + { + "attributes": { + "falseBody": null + }, + "children": [ + { + "attributes": { + "argumentTypes": null, + "commonType": { + "typeIdentifier": "t_address", + "typeString": "address" + }, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "operator": "==", + "type": "bool" + }, + "children": [ + { + "attributes": { + "argumentTypes": null, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "member_name": "sender", + "referencedDeclaration": null, + "type": "address payable" + }, + "children": [ + { + "attributes": { + "argumentTypes": null, + "overloadedDeclarations": [ + null + ], + "referencedDeclaration": 71, + "type": "msg", + "value": "msg" + }, + "id": 16, + "name": "Identifier", + "src": "209:3:0" + } + ], + "id": 17, + "name": "MemberAccess", + "src": "209:10:0" + }, + { + "attributes": { + "argumentTypes": null, + "overloadedDeclarations": [ + null + ], + "referencedDeclaration": 3, + "type": "address", + "value": "owner" + }, + "id": 18, + "name": "Identifier", + "src": "223:5:0" + } + ], + "id": 19, + "name": "BinaryOperation", + "src": "209:19:0" + }, + { + "id": 20, + "name": "PlaceholderStatement", + "src": "230:1:0" + } + ], + "id": 21, + "name": "IfStatement", + "src": "205:26:0" + } + ], + "id": 22, + "name": "Block", + "src": "199:37:0" } ], - "name": "setCompleted", - "nodeType": "FunctionDefinition", - "parameters": { - "id": 26, - "nodeType": "ParameterList", - "parameters": [ - { - "constant": false, - "id": 25, - "name": "completed", - "nodeType": "VariableDeclaration", - "scope": 35, - "src": "262:14:0", - "stateVariable": false, - "storageLocation": "default", - "typeDescriptions": { - "typeIdentifier": "t_uint256", - "typeString": "uint256" - }, - "typeName": { - "id": 24, - "name": "uint", - "nodeType": "ElementaryTypeName", - "src": "262:4:0", - "typeDescriptions": { - "typeIdentifier": "t_uint256", - "typeString": "uint256" - } - }, - "value": null, - "visibility": "internal" - } - ], - "src": "261:16:0" - }, - "returnParameters": { - "id": 29, - "nodeType": "ParameterList", - "parameters": [], - "src": "296:0:0" - }, - "scope": 56, - "src": "240:103:0", - "stateMutability": "nonpayable", - "superFunction": null, - "visibility": "public" + "id": 23, + "name": "ModifierDefinition", + "src": "177:59:0" }, { - "body": { - "id": 54, - "nodeType": "Block", - "src": "403:109:0", - "statements": [ - { - "assignments": [ - 43 - ], - "declarations": [ - { + "attributes": { + "documentation": null, + "implemented": true, + "isConstructor": false, + "kind": "function", + "name": "setCompleted", + "scope": 56, + "stateMutability": "nonpayable", + "superFunction": null, + "visibility": "public" + }, + "children": [ + { + "children": [ + { + "attributes": { "constant": false, - "id": 43, - "name": "upgraded", - "nodeType": "VariableDeclaration", - "scope": 54, - "src": "409:19:0", + "name": "completed", + "scope": 35, "stateVariable": false, "storageLocation": "default", - "typeDescriptions": { - "typeIdentifier": "t_contract$_Migrations_$56", - "typeString": "contract Migrations" - }, - "typeName": { - "contractScope": null, - "id": 42, - "name": "Migrations", - "nodeType": "UserDefinedTypeName", - "referencedDeclaration": 56, - "src": "409:10:0", - "typeDescriptions": { - "typeIdentifier": "t_contract$_Migrations_$56", - "typeString": "contract Migrations" - } - }, + "type": "uint256", "value": null, "visibility": "internal" - } - ], - "id": 47, - "initialValue": { - "argumentTypes": null, - "arguments": [ + }, + "children": [ { - "argumentTypes": null, - "id": 45, - "name": "new_address", - "nodeType": "Identifier", - "overloadedDeclarations": [], - "referencedDeclaration": 37, - "src": "442:11:0", - "typeDescriptions": { - "typeIdentifier": "t_address", - "typeString": "address" - } + "attributes": { + "name": "uint", + "type": "uint256" + }, + "id": 24, + "name": "ElementaryTypeName", + "src": "262:4:0" } ], - "expression": { - "argumentTypes": [ - { - "typeIdentifier": "t_address", - "typeString": "address" - } + "id": 25, + "name": "VariableDeclaration", + "src": "262:14:0" + } + ], + "id": 26, + "name": "ParameterList", + "src": "261:16:0" + }, + { + "attributes": { + "parameters": [ + null + ] + }, + "children": [], + "id": 29, + "name": "ParameterList", + "src": "296:0:0" + }, + { + "attributes": { + "arguments": null + }, + "children": [ + { + "attributes": { + "argumentTypes": null, + "overloadedDeclarations": [ + null ], - "id": 44, - "name": "Migrations", - "nodeType": "Identifier", - "overloadedDeclarations": [], - "referencedDeclaration": 56, - "src": "431:10:0", - "typeDescriptions": { - "typeIdentifier": "t_type$_t_contract$_Migrations_$56_$", - "typeString": "type(contract Migrations)" + "referencedDeclaration": 23, + "type": "modifier ()", + "value": "restricted" + }, + "id": 27, + "name": "Identifier", + "src": "285:10:0" + } + ], + "id": 28, + "name": "ModifierInvocation", + "src": "285:10:0" + }, + { + "children": [ + { + "children": [ + { + "attributes": { + "argumentTypes": null, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "operator": "=", + "type": "uint256" + }, + "children": [ + { + "attributes": { + "argumentTypes": null, + "overloadedDeclarations": [ + null + ], + "referencedDeclaration": 5, + "type": "uint256", + "value": "last_completed_migration" + }, + "id": 30, + "name": "Identifier", + "src": "302:24:0" + }, + { + "attributes": { + "argumentTypes": null, + "overloadedDeclarations": [ + null + ], + "referencedDeclaration": 25, + "type": "uint256", + "value": "completed" + }, + "id": 31, + "name": "Identifier", + "src": "329:9:0" + } + ], + "id": 32, + "name": "Assignment", + "src": "302:36:0" } + ], + "id": 33, + "name": "ExpressionStatement", + "src": "302:36:0" + } + ], + "id": 34, + "name": "Block", + "src": "296:47:0" + } + ], + "id": 35, + "name": "FunctionDefinition", + "src": "240:103:0" + }, + { + "attributes": { + "documentation": null, + "implemented": true, + "isConstructor": false, + "kind": "function", + "name": "upgrade", + "scope": 56, + "stateMutability": "nonpayable", + "superFunction": null, + "visibility": "public" + }, + "children": [ + { + "children": [ + { + "attributes": { + "constant": false, + "name": "new_address", + "scope": 55, + "stateVariable": false, + "storageLocation": "default", + "type": "address", + "value": null, + "visibility": "internal" }, - "id": 46, - "isConstant": false, - "isLValue": false, - "isPure": false, - "kind": "typeConversion", - "lValueRequested": false, - "names": [], - "nodeType": "FunctionCall", - "src": "431:23:0", - "typeDescriptions": { - "typeIdentifier": "t_contract$_Migrations_$56", - "typeString": "contract Migrations" - } - }, - "nodeType": "VariableDeclarationStatement", - "src": "409:45:0" - }, - { - "expression": { - "argumentTypes": null, - "arguments": [ + "children": [ { - "argumentTypes": null, - "id": 51, - "name": "last_completed_migration", - "nodeType": "Identifier", - "overloadedDeclarations": [], - "referencedDeclaration": 5, - "src": "482:24:0", - "typeDescriptions": { - "typeIdentifier": "t_uint256", - "typeString": "uint256" - } + "attributes": { + "name": "address", + "stateMutability": "nonpayable", + "type": "address" + }, + "id": 36, + "name": "ElementaryTypeName", + "src": "364:7:0" } ], - "expression": { - "argumentTypes": [ - { - "typeIdentifier": "t_uint256", - "typeString": "uint256" - } + "id": 37, + "name": "VariableDeclaration", + "src": "364:19:0" + } + ], + "id": 38, + "name": "ParameterList", + "src": "363:21:0" + }, + { + "attributes": { + "parameters": [ + null + ] + }, + "children": [], + "id": 41, + "name": "ParameterList", + "src": "403:0:0" + }, + { + "attributes": { + "arguments": null + }, + "children": [ + { + "attributes": { + "argumentTypes": null, + "overloadedDeclarations": [ + null ], - "expression": { - "argumentTypes": null, - "id": 48, - "name": "upgraded", - "nodeType": "Identifier", - "overloadedDeclarations": [], - "referencedDeclaration": 43, - "src": "460:8:0", - "typeDescriptions": { - "typeIdentifier": "t_contract$_Migrations_$56", - "typeString": "contract Migrations" - } + "referencedDeclaration": 23, + "type": "modifier ()", + "value": "restricted" + }, + "id": 39, + "name": "Identifier", + "src": "392:10:0" + } + ], + "id": 40, + "name": "ModifierInvocation", + "src": "392:10:0" + }, + { + "children": [ + { + "attributes": { + "assignments": [ + 43 + ] + }, + "children": [ + { + "attributes": { + "constant": false, + "name": "upgraded", + "scope": 54, + "stateVariable": false, + "storageLocation": "default", + "type": "contract Migrations", + "value": null, + "visibility": "internal" + }, + "children": [ + { + "attributes": { + "contractScope": null, + "name": "Migrations", + "referencedDeclaration": 56, + "type": "contract Migrations" + }, + "id": 42, + "name": "UserDefinedTypeName", + "src": "409:10:0" + } + ], + "id": 43, + "name": "VariableDeclaration", + "src": "409:19:0" }, - "id": 50, - "isConstant": false, - "isLValue": false, - "isPure": false, - "lValueRequested": false, - "memberName": "setCompleted", - "nodeType": "MemberAccess", - "referencedDeclaration": 35, - "src": "460:21:0", - "typeDescriptions": { - "typeIdentifier": "t_function_external_nonpayable$_t_uint256_$returns$__$", - "typeString": "function (uint256) external" + { + "attributes": { + "argumentTypes": null, + "isConstant": false, + "isLValue": false, + "isPure": false, + "isStructConstructorCall": false, + "lValueRequested": false, + "names": [ + null + ], + "type": "contract Migrations", + "type_conversion": true + }, + "children": [ + { + "attributes": { + "argumentTypes": [ + { + "typeIdentifier": "t_address", + "typeString": "address" + } + ], + "overloadedDeclarations": [ + null + ], + "referencedDeclaration": 56, + "type": "type(contract Migrations)", + "value": "Migrations" + }, + "id": 44, + "name": "Identifier", + "src": "431:10:0" + }, + { + "attributes": { + "argumentTypes": null, + "overloadedDeclarations": [ + null + ], + "referencedDeclaration": 37, + "type": "address", + "value": "new_address" + }, + "id": 45, + "name": "Identifier", + "src": "442:11:0" + } + ], + "id": 46, + "name": "FunctionCall", + "src": "431:23:0" } - }, - "id": 52, - "isConstant": false, - "isLValue": false, - "isPure": false, - "kind": "functionCall", - "lValueRequested": false, - "names": [], - "nodeType": "FunctionCall", - "src": "460:47:0", - "typeDescriptions": { - "typeIdentifier": "t_tuple$__$", - "typeString": "tuple()" - } + ], + "id": 47, + "name": "VariableDeclarationStatement", + "src": "409:45:0" }, - "id": 53, - "nodeType": "ExpressionStatement", - "src": "460:47:0" - } - ] - }, - "documentation": null, - "id": 55, - "implemented": true, - "kind": "function", - "modifiers": [ - { - "arguments": null, - "id": 40, - "modifierName": { - "argumentTypes": null, - "id": 39, - "name": "restricted", - "nodeType": "Identifier", - "overloadedDeclarations": [], - "referencedDeclaration": 23, - "src": "392:10:0", - "typeDescriptions": { - "typeIdentifier": "t_modifier$__$", - "typeString": "modifier ()" + { + "children": [ + { + "attributes": { + "argumentTypes": null, + "isConstant": false, + "isLValue": false, + "isPure": false, + "isStructConstructorCall": false, + "lValueRequested": false, + "names": [ + null + ], + "type": "tuple()", + "type_conversion": false + }, + "children": [ + { + "attributes": { + "argumentTypes": [ + { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + ], + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "member_name": "setCompleted", + "referencedDeclaration": 35, + "type": "function (uint256) external" + }, + "children": [ + { + "attributes": { + "argumentTypes": null, + "overloadedDeclarations": [ + null + ], + "referencedDeclaration": 43, + "type": "contract Migrations", + "value": "upgraded" + }, + "id": 48, + "name": "Identifier", + "src": "460:8:0" + } + ], + "id": 50, + "name": "MemberAccess", + "src": "460:21:0" + }, + { + "attributes": { + "argumentTypes": null, + "overloadedDeclarations": [ + null + ], + "referencedDeclaration": 5, + "type": "uint256", + "value": "last_completed_migration" + }, + "id": 51, + "name": "Identifier", + "src": "482:24:0" + } + ], + "id": 52, + "name": "FunctionCall", + "src": "460:47:0" + } + ], + "id": 53, + "name": "ExpressionStatement", + "src": "460:47:0" } - }, - "nodeType": "ModifierInvocation", - "src": "392:10:0" + ], + "id": 54, + "name": "Block", + "src": "403:109:0" } ], - "name": "upgrade", - "nodeType": "FunctionDefinition", - "parameters": { - "id": 38, - "nodeType": "ParameterList", - "parameters": [ - { - "constant": false, - "id": 37, - "name": "new_address", - "nodeType": "VariableDeclaration", - "scope": 55, - "src": "364:19:0", - "stateVariable": false, - "storageLocation": "default", - "typeDescriptions": { - "typeIdentifier": "t_address", - "typeString": "address" - }, - "typeName": { - "id": 36, - "name": "address", - "nodeType": "ElementaryTypeName", - "src": "364:7:0", - "stateMutability": "nonpayable", - "typeDescriptions": { - "typeIdentifier": "t_address", - "typeString": "address" - } - }, - "value": null, - "visibility": "internal" - } - ], - "src": "363:21:0" - }, - "returnParameters": { - "id": 41, - "nodeType": "ParameterList", - "parameters": [], - "src": "403:0:0" - }, - "scope": 56, - "src": "347:165:0", - "stateMutability": "nonpayable", - "superFunction": null, - "visibility": "public" + "id": 55, + "name": "FunctionDefinition", + "src": "347:165:0" } ], - "scope": 57, + "id": 56, + "name": "ContractDefinition", "src": "34:480:0" } ], + "id": 57, + "name": "SourceUnit", "src": "0:515:0" }, "compiler": { @@ -1381,24 +1475,24 @@ "3": { "events": {}, "links": {}, - "address": "0xB18D4a5D7bc8450A957f7AD1675D5e606d4482B0", - "transactionHash": "0xbccea19bc11581ce2d400d85486433b5a133a60a6ebcaa7e41141e6892e14a40" + "address": "0xfeDa07B32086f369f2c80c612B4d235C83634fA0", + "transactionHash": "0x602997f62bc4c24783dd387b0aa53459cf01ff7e3445c5a885e5c9bbd893def6" }, "4": { "events": {}, "links": {}, - "address": "0x268eB824A623AAe2a1A0cf55aEf5381a4f965F3d", - "transactionHash": "0x6246d9d700fc6d0e5cbd3225b8252f60c832002c31ca78ec9eebcbdb3b024763" + "address": "0xe77F883BE0305f1D8cF882efe0a5Ae7b09dE7102", + "transactionHash": "0x1695ed5a2f245dfde12f51f7ee7e082722dfe23ff1898d5f2ca96647954cc1db" }, "5777": { "events": {}, "links": {}, - "address": "0xea1b53f388549B29251A1eCcfF1553F5C32a5D23", - "transactionHash": "0xf65d5c1fef5d9b8b246ce5565492417d07a3f0ca8cb2db8ce2f50487ab59f0b1" + "address": "0x48d22b29fCFfcdd453B11103BdB832C40bFceeb8", + "transactionHash": "0x6b2cf62b26e46c1d957b4afaf8fd72dcc2082d3e4cfbc7703f67ecb50d426875" } }, "schemaVersion": "3.4.1", - "updatedAt": "2021-05-28T09:00:04.258Z", + "updatedAt": "2021-05-28T11:43:29.217Z", "networkType": "ethereum", "devdoc": { "methods": {} diff --git a/src/abis/TestToken.json b/src/abis/TestToken.json index 0de7c0f..de3e67f 100644 --- a/src/abis/TestToken.json +++ b/src/abis/TestToken.json @@ -4962,8 +4962,8 @@ } }, "links": {}, - "address": "0xC8B88a647b0c3D2CCce7bD561C8285c1FaA79b15", - "transactionHash": "0xc048a73f0cf6cf074f5dd56d45a77850b43abdaa6e76c9179db32452220e515f" + "address": "0x0190f80487179053eb85451454541644AbAf4048", + "transactionHash": "0x2e843110db9670da170a5f6622f8a14d75a29ff12371a0e89f90e76790b5bd16" }, "4": { "events": { @@ -5019,8 +5019,8 @@ } }, "links": {}, - "address": "0x00BaE190Cf151ACc11EE207e03f368A058dE737F", - "transactionHash": "0x8bb529cdeb7adaf8b8bd151a8af239b6fca07647bdfcb51e92800a4ba3438331" + "address": "0xb54039DAC3C4ADdAC082e86a6e9C290E80af9488", + "transactionHash": "0x3d42409a37ddbb49617cdcda1dbfc999118b2a263b8dc371d667cc527f1aa4ab" }, "5777": { "events": { @@ -5076,12 +5076,12 @@ } }, "links": {}, - "address": "0x7fB6B75953f12B2b835A6088451A28748Bd4a7f6", - "transactionHash": "0x09783c4c5b16600d86512f39d0913e59d067587776af3ed5aa2d6d9ca99b66dd" + "address": "0xB30BF369C21946928a9f54d55654b890BD846144", + "transactionHash": "0x10db965396deebfdc77966feddb7062f0ad1e58388150475ce3cb27084832a52" } }, "schemaVersion": "3.4.1", - "updatedAt": "2021-05-28T09:00:04.230Z", + "updatedAt": "2021-05-28T11:43:29.192Z", "networkType": "ethereum", "devdoc": { "methods": {} diff --git a/src/abis/TokenStaking.json b/src/abis/TokenStaking.json index 5d74d0c..e97b5c5 100644 --- a/src/abis/TokenStaking.json +++ b/src/abis/TokenStaking.json @@ -12889,24 +12889,24 @@ "3": { "events": {}, "links": {}, - "address": "0xABa3314745b3eBCF91Eb4a61f695fc55B81119eF", - "transactionHash": "0x2d529477aa1c5895c5c7e070a3e33e3d5f9972d9ff3dfe0fcbd1ee11b8e0a2dd" + "address": "0x0Fab2A018bB44DD2a6Ef7C55F057Dd9d9eC1B19F", + "transactionHash": "0x66affe9ddcc853734e4a76bbf34fc09b29f379bc9a57339223ba2d0d8b5249db" }, "4": { "events": {}, "links": {}, - "address": "0x1812f820eB5C9245eDc0f0D849963af955406559", - "transactionHash": "0x6c3f239f7d89a74eb71e65961f520a8278534900625dbe916402d63643e10746" + "address": "0xAf9352B33E9B08A86dD04fcD8533DbC75BD2c8d1", + "transactionHash": "0x79d5f4128c390d2f182b27e374c52f971d67f5662169a92b448f07033f48ef54" }, "5777": { "events": {}, "links": {}, - "address": "0xE1B5d743384BE7145EDfBc54F5F56201b30b41Db", - "transactionHash": "0x142741ff1521ea9475ee038a51ee5abfafea022be7229c5598de0fea5b463e1b" + "address": "0xa673988ED5E8b8A016935cF7612B0F390A228487", + "transactionHash": "0x5648d3ea3809a778921de8fbd61a0cdaab707f2f5c8dcbb2b32cc3969818fb94" } }, "schemaVersion": "3.4.1", - "updatedAt": "2021-05-28T09:00:04.244Z", + "updatedAt": "2021-05-28T11:43:29.206Z", "networkType": "ethereum", "devdoc": { "methods": {} diff --git a/test/TokenStaking.js b/test/TokenStaking.js index 303be78..02b0880 100644 --- a/test/TokenStaking.js +++ b/test/TokenStaking.js @@ -79,7 +79,7 @@ contract('TokenStaking', ([creator, user]) => { ); }); - //3.2 checking TokenStaking total banalce + // 3.2 checking TokenStaking total banalce it('checking total staked before any stakes', async () => { result = await tokenStaking.totalStaked(); assert.equal( @@ -91,14 +91,14 @@ contract('TokenStaking', ([creator, user]) => { // 3.3 Testing stakeTokens function it('aproving tokens, staking tokens, checking balance', async () => { - //first aprove tokens to be staked + // first aprove tokens to be staked await testToken.approve(tokenStaking.address, tokenCorvert('1000'), { from: user, }); - //stake tokens + // stake tokens await tokenStaking.stakeTokens(tokenCorvert('1000'), { from: user }); - //check balance of user if they have 0 after staking + // check balance of user if they have 0 after staking result = await testToken.balanceOf(user); assert.equal( result.toString(), @@ -107,7 +107,7 @@ contract('TokenStaking', ([creator, user]) => { ); }); - //3.4 checking balance of TokenStaking contract should be 500k +1000 + // 3.4 checking balance of TokenStaking contract should be 500k +1000 it('checking contract balance after staking', async () => { result = await testToken.balanceOf(tokenStaking.address); assert.equal( @@ -117,7 +117,7 @@ contract('TokenStaking', ([creator, user]) => { ); }); - //3.5 checking TokenStaking contract users balance + // 3.5 checking TokenStaking contract users balance it('checking user balance inside contract', async () => { result = await tokenStaking.stakingBalance(user); assert.equal( @@ -127,7 +127,7 @@ contract('TokenStaking', ([creator, user]) => { ); }); - //3.6 checking TokenStaking totalstaked balance + // 3.6 checking TokenStaking totalstaked balance it('checking total staked', async () => { result = await tokenStaking.totalStaked(); assert.equal( @@ -137,20 +137,20 @@ contract('TokenStaking', ([creator, user]) => { ); }); - //3.7 checking isStaking function to see if user is staking + // 3.7 checking isStaking function to see if user is staking it('testing if user is staking at the moment', async () => { result = await tokenStaking.isStakingAtm(user); assert.equal(result.toString(), 'true', 'user is currently staking'); }); - //3.8 checking hasStaked function to see if user ever staked + // 3.8 checking hasStaked function to see if user ever staked it('testing if user has staked', async () => { result = await tokenStaking.hasStaked(user); assert.equal(result.toString(), 'true', 'user has staked'); }); }); - //Test 4 + // Test 4 describe('TokenStaking redistributeRewards function', async () => { let result; // 4.1 checking who can issue tokens @@ -197,7 +197,7 @@ contract('TokenStaking', ([creator, user]) => { ); }); - //5.2 checking TokenStaking total staked balance + // 5.2 checking TokenStaking total staked balance it('checking total staked', async () => { result = await tokenStaking.totalStaked(); assert.equal( @@ -208,12 +208,10 @@ contract('TokenStaking', ([creator, user]) => { }); }); - //Test 6 + // Test 6 describe('TokenStaking [custom] staking/unstaking functions', async () => { let result; - // New test - - //6.1 checking TokenStaking total custom staking banalce + // 6.1 checking TokenStaking total custom staking banalce it('checking total custom staked before any stakes', async () => { result = await tokenStaking.customTotalStaked(); assert.equal( @@ -223,7 +221,7 @@ contract('TokenStaking', ([creator, user]) => { ); }); - //6.2 checking Users Balance before staking + // 6.2 checking Users Balance before staking it('checking usrs balance before staking', async () => { result = await testToken.balanceOf(user); assert.equal( @@ -233,16 +231,16 @@ contract('TokenStaking', ([creator, user]) => { ); }); - //6.3 testing if user able to stake in custom staking + // 6.3 testing if user able to stake in custom staking it('aproving tokens, staking tokens, checking balance', async () => { - //first aprove tokens to be staked + // first aprove tokens to be staked await testToken.approve(tokenStaking.address, tokenCorvert('1234'), { from: user, }); - //stake tokens + // stake tokens await tokenStaking.customStaking(tokenCorvert('1234'), { from: user }); - //check balance of user if they have 1001 after staking + // check balance of user if they have 1001 after staking result = await testToken.balanceOf(user); assert.equal( result.toString(), @@ -251,7 +249,7 @@ contract('TokenStaking', ([creator, user]) => { ); }); - //6.4 check custom total staking balance + // 6.4 check custom total staking balance it('checking custom total staked', async () => { result = await tokenStaking.customTotalStaked(); assert.equal( @@ -261,19 +259,19 @@ contract('TokenStaking', ([creator, user]) => { ); }); - //6.5 checking customIsStakingAtm function to see if user is staking + // 6.5 checking customIsStakingAtm function to see if user is staking it('testing if user is staking at custom staking at the moment', async () => { result = await tokenStaking.customIsStakingAtm(user); assert.equal(result.toString(), 'true', 'user is currently staking'); }); - //6.6 checking customHasStaked function to see if user ever staked + // 6.6 checking customHasStaked function to see if user ever staked it('testing if user has staked at custom staking', async () => { result = await tokenStaking.customHasStaked(user); assert.equal(result.toString(), 'true', 'user has staked'); }); - //6.7 unstaking from custom staking and checking balance + // 6.7 unstaking from custom staking and checking balance it('unstaking from custom staking and checking users balance ', async () => { await tokenStaking.customUnstake({ from: user }); result = await testToken.balanceOf(user); @@ -288,7 +286,7 @@ contract('TokenStaking', ([creator, user]) => { // Test 7 describe('Claim Tst', async () => { let result; - // testing claim test token function + // 7.1 testing claim test token function it('trying to obtain 1000 test token', async () => { await tokenStaking.claimTst({ from: user }); @@ -297,14 +295,14 @@ contract('TokenStaking', ([creator, user]) => { }); }); - //Test 8 + // Test 8 describe('Change custom APY value', async () => { let result; - //8.1 testing who can change custom APY + // 8.1 testing who can change custom APY it('checking who can change APY', async () => { await tokenStaking.changeAPY('200', { from: creator }); - //testing with invalid arguments + // testing with invalid arguments await tokenStaking.changeAPY({ from: creator }).should.be.rejected; await tokenStaking.changeAPY(tokenCorvert('0'), { from: creator }).should .be.rejected; @@ -312,12 +310,49 @@ contract('TokenStaking', ([creator, user]) => { .be.rejected; }); - //8.2 checking New custom APY value + // 8.2 checking New custom APY value it('checking new custom APY value', async () => { const value = await tokenStaking.customAPY(); assert.equal(value, '200', 'custom APY set to 200 (0.2% Daily)'); }); }); + + // Test 9 + describe('Testing custom APY reward redistribution', async () => { + let result; + // 9.1 redistributing custom APY rewards + it('staking at customStaking', async () => { + await testToken.approve(tokenStaking.address, tokenCorvert('1000'), { + from: user, + }); + // stake tokens + await tokenStaking.customStaking(tokenCorvert('1000'), { from: user }); + // checking user balance after staking + result = await testToken.balanceOf(user); + assert.equal( + result.toString(), + tokenCorvert('2235'), + 'User balance after unstaking 3235 - 1000' + ); + }); + // 9.2 issuing custom rewards + it('redistributing rewards, checking who can redistribute', async () => { + // issue customRewards function from creator + await tokenStaking.customRewards({ from: creator }); + + // issue customRewards function from user, should not be able + await tokenStaking.customRewards({ from: user }).should.be.rejected; + }); + // 9.2 checking new user balance after custom rewards + it('checking user balance after custom APY rewards ', async () => { + result = await testToken.balanceOf(user); + assert.equal( + result.toString(), + tokenCorvert('2237'), + 'User balance after unstaking 2235 + 2' + ); + }); + }); }); //to run test - truffle test