Skip to content

Commit

Permalink
Merge pull request #75 from tellor-io/update-playground
Browse files Browse the repository at this point in the history
update playground, add addStakingRewards mock
  • Loading branch information
themandalore authored Jun 13, 2022
2 parents 4f3c02b + d09f820 commit d5189f8
Show file tree
Hide file tree
Showing 14 changed files with 39,896 additions and 72,723 deletions.
66,418 changes: 0 additions & 66,418 deletions artifacts/build-info/36ee78c35dcd78904a34854a6c480231.json

This file was deleted.

Large diffs are not rendered by default.

35,120 changes: 35,120 additions & 0 deletions artifacts/build-info/d46c8c3bbd24a5104f77a50713652796.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/d8bc9c4dcbff4f4633ec10b95ecc3bd9.json"
"buildInfo": "../../build-info/969f1b7b30f0a731a9f9b0dc921a9161.json"
}
60 changes: 15 additions & 45 deletions artifacts/contracts/TellorPlayground.sol/TellorPlayground.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion artifacts/contracts/UsingTellor.sol/UsingTellor.dbg.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/36ee78c35dcd78904a34854a6c480231.json"
"buildInfo": "../../build-info/d46c8c3bbd24a5104f77a50713652796.json"
}
4 changes: 2 additions & 2 deletions artifacts/contracts/UsingTellor.sol/UsingTellor.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion artifacts/contracts/interface/ITellor.sol/ITellor.dbg.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/36ee78c35dcd78904a34854a6c480231.json"
"buildInfo": "../../../build-info/d46c8c3bbd24a5104f77a50713652796.json"
}
13 changes: 13 additions & 0 deletions artifacts/contracts/interface/ITellor.sol/ITellor.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
"contractName": "ITellor",
"sourceName": "contracts/interface/ITellor.sol",
"abi": [
{
"inputs": [
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
}
],
"name": "addStakingRewards",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/36ee78c35dcd78904a34854a6c480231.json"
"buildInfo": "../../../build-info/d46c8c3bbd24a5104f77a50713652796.json"
}

Large diffs are not rendered by default.

45 changes: 11 additions & 34 deletions contracts/TellorPlayground.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ contract TellorPlayground {
bytes32 _queryId,
uint256 _time,
bytes _value,
uint256 _reward,
uint256 _nonce,
bytes _queryData,
address _reporter
Expand Down Expand Up @@ -42,7 +41,6 @@ contract TellorPlayground {
mapping(address => uint256) private _balances;

uint256 public constant timeBasedReward = 5e17; // time based reward for a reporter for successfully submitting a value
uint256 public timeOfLastNewValue = block.timestamp; // time of the last new value, originally set to the block timestamp
uint256 public tipsInContract; // number of tips within the contract
uint256 public voteCount;
uint256 private _totalSupply;
Expand Down Expand Up @@ -72,6 +70,14 @@ contract TellorPlayground {
] = address(this);
}

/**
* @dev Mock function for adding staking rewards
* @param _amount quantity of tokens to transfer to this contract
*/
function addStakingRewards(uint256 _amount) external {
require(_transferFrom(msg.sender, address(this), _amount));
}

/**
* @dev Approves amount that an address is alowed to spend of behalf of another
* @param _spender The address which is allowed to spend the tokens
Expand Down Expand Up @@ -125,31 +131,22 @@ contract TellorPlayground {
bytes memory _queryData
) external {
require(
_nonce == timestamps[_queryId].length,
"nonce should be correct"
_nonce == timestamps[_queryId].length || _nonce == 0,
"nonce must match timestamp index"
);
require(
_queryId == keccak256(_queryData) || uint256(_queryId) <= 100,
"id must be hash of bytes data"
);
values[_queryId][block.timestamp] = _value;
timestamps[_queryId].push(block.timestamp);
// Send tips + timeBasedReward to reporter and reset tips for ID
(uint256 _tip, uint256 _reward) = getCurrentReward(_queryId);
if (_reward + _tip > 0) {
transfer(msg.sender, _reward + _tip);
}
timeOfLastNewValue = block.timestamp;
tipsInContract -= _tip;
tips[_queryId] = 0;
reporterByTimestamp[_queryId][block.timestamp] = msg.sender;
stakerDetails[msg.sender].reporterLastTimestamp = block.timestamp;
stakerDetails[msg.sender].reportsSubmitted++;
emit NewReport(
_queryId,
block.timestamp,
_value,
_tip + _reward,
_nonce,
_queryData,
msg.sender
Expand Down Expand Up @@ -354,26 +351,6 @@ contract TellorPlayground {
return _decimals;
}

/**
* @dev Calculates the current reward for a reporter given tips and time based reward
* @param _queryId is ID of the specific data feed
* @return uint256 tip amount for given query ID
* @return uint256 time based reward
*/
// slither-disable-next-line timestamp
function getCurrentReward(bytes32 _queryId)
public
view
returns (uint256, uint256)
{
uint256 _timeDiff = block.timestamp - timeOfLastNewValue;
uint256 _reward = (_timeDiff * timeBasedReward) / 300; //.5 TRB per 5 minutes (should we make this upgradeable)
if (balanceOf(address(this)) < _reward + tipsInContract) {
_reward = balanceOf(address(this)) - tipsInContract;
}
return (tips[_queryId], _reward);
}

/**
* @dev Counts the number of values that have been submitted for a given ID
* @param _queryId the ID to look up
Expand Down Expand Up @@ -545,4 +522,4 @@ contract TellorPlayground {
);
return true;
}
}
}
3 changes: 3 additions & 0 deletions contracts/interface/ITellor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ interface ITellor{
function rescue51PercentAttack(address _tokenHolder) external;
function rescueBrokenDataReporting() external;
function rescueFailedUpdate() external;

//Tellor 360
function addStakingRewards(uint256 _amount) external;
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d5189f8

Please sign in to comment.