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

test fix contract & add error data when send tx failed #715

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1,370 changes: 232 additions & 1,138 deletions smartcontracts/.openzeppelin/unknown-4690.json

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions smartcontracts/contracts/W3bstreamBlockMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {ITaskManager, TaskAssignment} from "./interfaces/ITaskManager.sol";

interface IDAO {
function tip() external view returns (uint256, bytes32, uint256);

function mint(bytes32 hash, uint256 timestamp) external;
}

Expand Down Expand Up @@ -34,7 +35,12 @@ contract W3bstreamBlockMinter is OwnableUpgradeable {
uint256 public blockReward;
uint256 public taskAllowance;

function initialize(IDAO _dao, ITaskManager _taskManager, IBlockRewardDistributor _distributor, IBlockHeaderValidator _headerValidator) public initializer {
function initialize(
IDAO _dao,
ITaskManager _taskManager,
IBlockRewardDistributor _distributor,
IBlockHeaderValidator _headerValidator
) public initializer {
__Ownable_init();
dao = _dao;
taskManager = _taskManager;
Expand All @@ -50,14 +56,17 @@ contract W3bstreamBlockMinter is OwnableUpgradeable {
TaskAssignment[] calldata assignments
) public {
require(coinbase.operator == msg.sender, "invalid operator");
(, bytes32 tiphash, uint256 tipTimestamp) = dao.tip();
require(tipTimestamp != block.number);
(uint256 tipBlockNumber, bytes32 tiphash, ) = dao.tip();
require(tipBlockNumber != block.number);
require(header.prevhash == tiphash, "invalid prevhash");
require(header.merkleRoot == keccak256(abi.encode(coinbase.addr, coinbase.operator, coinbase.beneficiary)), "invalid merkle root");
require(
header.merkleRoot == keccak256(abi.encode(coinbase.addr, coinbase.operator, coinbase.beneficiary)),
"invalid merkle root"
);
bytes memory encodedHeader = headerValidator.validate(header);
bytes32 blockHash = keccak256(abi.encode(encodedHeader, assignments));
taskManager.assign(assignments, coinbase.beneficiary, block.number + taskAllowance);
headerValidator.updateDuration(block.number - tipTimestamp);
headerValidator.updateDuration(block.number - tipBlockNumber);
dao.mint(blockHash, block.number);
distributor.distribute(coinbase.beneficiary, blockReward);
}
Expand Down
8 changes: 6 additions & 2 deletions smartcontracts/contracts/W3bstreamProjectReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IProject {
function ownerOf(uint256 _projectId) external view returns (address);

function isPaused(uint256 _projectId) external view returns (bool);
}

Expand All @@ -23,7 +24,7 @@ contract W3bstreamProjectReward is OwnableUpgradeable {
modifier onlyOperator() {
require(msg.sender == operator, "not operator");
_;
}
}

function initialize(address _project) public initializer {
__Ownable_init();
Expand All @@ -34,6 +35,10 @@ contract W3bstreamProjectReward is OwnableUpgradeable {
return _rewardTokens[_id];
}

function rewardAmount(address owner, uint256 id) external view returns (uint256) {
return _rewardAmounts[owner][id];
}

function isPaused(uint256 _projectId) external view returns (bool) {
return IProject(project).isPaused(_projectId);
}
Expand All @@ -51,5 +56,4 @@ contract W3bstreamProjectReward is OwnableUpgradeable {
_rewardAmounts[sender][_id] = _amount;
emit RewardAmountSet(sender, _id, _amount);
}

}
138 changes: 53 additions & 85 deletions smartcontracts/contracts/W3bstreamProver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,117 +2,85 @@
pragma solidity ^0.8.19;

import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";

contract W3bstreamProver is OwnableUpgradeable, ERC721Upgradeable {
event OperatorSet(uint256 indexed id, address indexed operator);
event VMTypeAdded(uint256 indexed id, uint256 typ);
event VMTypeDeleted(uint256 indexed id, uint256 typ);
event ProverPaused(uint256 indexed id);
event ProverResumed(uint256 indexed id);
event MinterSet(address minter);

address public minter;
uint256 nextProverId;

mapping(uint256 => mapping(uint256 => bool)) _vmTypes;
mapping(uint256 => address) _operators;
mapping(uint256 => bool) _paused;
mapping(address => uint256) operatorToProver;

modifier onlyProverOwner(uint256 _id) {
require(ownerOf(_id) == msg.sender, "not owner");
_;
}

function initialize(string memory _name, string memory _symbol) public initializer {
__Ownable_init();
__ERC721_init(_name, _symbol);
setMinter(msg.sender);
}

function count() external view returns (uint256) {
return nextProverId;
}
contract W3bstreamProver is OwnableUpgradeable {
event BeneficiarySet(address indexed prover, address indexed beneficiary);
event VMTypeAdded(address indexed prover, uint256 typ);
event VMTypeDeleted(address indexed prover, uint256 typ);
event ProverPaused(address indexed prover);
event ProverResumed(address indexed prover);
event RebateRatioSet(address indexed prover, uint16 ratio);

function isVMTypeSupported(uint256 _id, uint256 _type) external view returns (bool) {
_requireMinted(_id);
return _vmTypes[_id][_type];
}
mapping(address => mapping(uint256 => bool)) vmTypes;
mapping(address => uint16) rebateRatios;
mapping(address => address) beneficiaries;
mapping(address => bool) paused;

function operator(uint256 _id) external view returns (address) {
_requireMinted(_id);
return _operators[_id];
function initialize() public initializer {
__Ownable_init();
}

function prover(uint256 _id) external view returns (address) {
_requireMinted(_id);
return ownerOf(_id);
function isVMTypeSupported(address _prover, uint256 _type) external view returns (bool) {
return vmTypes[_prover][_type];
}

function ownerOfOperator(address _operator) external view returns (uint256, address) {
uint256 id = operatorToProver[_operator];
require(id != 0, "invalid operator");
return (id, ownerOf(id));
function beneficiary(address _prover) external view returns (address) {
return beneficiaries[_prover];
}

function isPaused(uint256 _id) external view returns (bool) {
_requireMinted(_id);
return _paused[_id];
function isPaused(address _prover) external view returns (bool) {
return paused[_prover];
}

function mint(address _account) external returns (uint256 id_) {
require(msg.sender == minter, "not minter");

id_ = ++nextProverId;
_mint(_account, id_);

_paused[id_] = true;
updateOperatorInternal(id_, _account);
function rebateRatio(address _prover) external view returns (uint16) {
return rebateRatios[_prover];
}

function updateOperatorInternal(uint256 _id, address _operator) internal {
uint256 proverId = operatorToProver[_operator];
require(proverId == 0, "invalid operator");
address oldOperator = _operators[_id];
_operators[_id] = _operator;
delete operatorToProver[oldOperator];
operatorToProver[_operator] = _id;
emit OperatorSet(_id, _operator);
function register() external {
address sender = msg.sender;
require(beneficiaries[sender] == address(0), "already registered");
beneficiaries[sender] = sender;
emit BeneficiarySet(sender, sender);
}

function addVMType(uint256 _id, uint256 _type) external onlyProverOwner(_id) {
_vmTypes[_id][_type] = true;
emit VMTypeAdded(_id, _type);
function setRebateRatio(uint16 _ratio) external {
address sender = msg.sender;
rebateRatios[sender] = _ratio;
emit RebateRatioSet(sender, _ratio);
}

function delVMType(uint256 _id, uint256 _type) external onlyProverOwner(_id) {
_vmTypes[_id][_type] = false;
emit VMTypeDeleted(_id, _type);
function addVMType(uint256 _type) external {
address sender = msg.sender;
vmTypes[sender][_type] = true;
emit VMTypeAdded(sender, _type);
}

function changeOperator(uint256 _id, address _operator) external onlyProverOwner(_id) {
require(_operator != address(0), "zero address");
updateOperatorInternal(_id, _operator);
function delVMType(uint256 _type) external {
address sender = msg.sender;
vmTypes[sender][_type] = false;
emit VMTypeDeleted(sender, _type);
}

function pause(uint256 _id) external onlyProverOwner(_id) {
require(!_paused[_id], "already paused");

_paused[_id] = true;
emit ProverPaused(_id);
function changeBeneficiary(address _beneficiary) external {
address sender = msg.sender;
require(_beneficiary != address(0), "zero address");
beneficiaries[sender] = _beneficiary;
emit BeneficiarySet(sender, _beneficiary);
}

function resume(uint256 _id) external onlyProverOwner(_id) {
require(_paused[_id], "already actived");
function pause() external {
address sender = msg.sender;
require(!paused[sender], "already paused");

_paused[_id] = false;
emit ProverResumed(_id);
paused[sender] = true;
emit ProverPaused(sender);
}

function setMinter(address _minter) public onlyOwner {
minter = _minter;
function resume() external {
address sender = msg.sender;
require(paused[sender], "already actived");

emit MinterSet(_minter);
paused[sender] = false;
emit ProverResumed(sender);
}
}
86 changes: 0 additions & 86 deletions smartcontracts/contracts/W3bstreamProver2.sol

This file was deleted.

Loading
Loading