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

Added possibility to use ERC20 Neuro for Knowledge Mining Incentivization #286

Merged
merged 16 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions abi/ParanetIncentivesPoolFactory.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
},
{
"inputs": [
{
"internalType": "bool",
"name": "isNativeReward",
"type": "bool"
},
{
"internalType": "address",
"name": "paranetKAStorageContract",
Expand Down
69 changes: 50 additions & 19 deletions abi/ParanetNeuroIncentivesPool.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"name": "hubAddress",
"type": "address"
},
{
"internalType": "address",
"name": "rewardTokenAddress",
"type": "address"
},
{
"internalType": "address",
"name": "paranetsRegistryAddress",
Expand Down Expand Up @@ -81,19 +86,19 @@
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "oldMultiplier",
"type": "uint256"
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "newMultiplier",
"name": "amount",
"type": "uint256"
}
],
"name": "NeuroEmissionMultiplierUpdateFinalized",
"name": "NativeNeuroRewardDeposit",
"type": "event"
},
{
Expand All @@ -110,34 +115,34 @@
"internalType": "uint256",
"name": "newMultiplier",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
}
],
"name": "NeuroEmissionMultiplierUpdateInitiated",
"name": "NeuroEmissionMultiplierUpdateFinalized",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
"indexed": false,
"internalType": "uint256",
"name": "oldMultiplier",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"name": "newMultiplier",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
}
],
"name": "NeuroRewardDeposit",
"name": "NeuroEmissionMultiplierUpdateInitiated",
"type": "event"
},
{
Expand Down Expand Up @@ -715,6 +720,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "isNativeNeuro",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -924,6 +942,19 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "token",
"outputs": [
{
"internalType": "contract IERC20",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalMinersClaimedNeuro",
Expand Down
2 changes: 1 addition & 1 deletion contracts/v2/constants/ParanetIncentivesPoolConstants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.16;

uint24 constant TOKENS_DIGITS_DIFF = 10 ** 6;
uint24 constant NATIVE_NEURO_DECIMALS_DIFF = 10 ** 6;
uint64 constant EMISSION_MULTIPLIER_SCALING_FACTOR = 10 ** 18;
uint16 constant PERCENTAGE_SCALING_FACTOR = 10 ** 4;
uint16 constant MAX_CUMULATIVE_VOTERS_WEIGHT = 10 ** 4;
13 changes: 8 additions & 5 deletions contracts/v2/paranets/ParanetIncentivesPoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ contract ParanetIncentivesPoolFactory is Named, Versioned, ContractStatusV2, Ini
}

function deployNeuroIncentivesPool(
bool isNativeReward,
address paranetKAStorageContract,
uint256 paranetKATokenId,
uint256 tracToNeuroEmissionMultiplier,
Expand All @@ -54,26 +55,28 @@ contract ParanetIncentivesPoolFactory is Named, Versioned, ContractStatusV2, Ini
) external onlyKnowledgeAssetOwner(paranetKAStorageContract, paranetKATokenId) returns (address) {
HubV2 h = hub;
ParanetsRegistry pr = paranetsRegistry;
string memory incentivesPoolType = isNativeReward ? "Neuroweb" : "NeurowebERC20";
u-hubar marked this conversation as resolved.
Show resolved Hide resolved

if (
pr.hasIncentivesPoolByType(
keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)),
"Neuroweb"
incentivesPoolType
)
) {
revert ParanetErrors.ParanetIncentivesPoolAlreadyExists(
paranetKAStorageContract,
paranetKATokenId,
"Neuroweb",
incentivesPoolType,
pr.getIncentivesPoolAddress(
keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)),
"Neuroweb"
incentivesPoolType
)
);
}

ParanetNeuroIncentivesPool incentivesPool = new ParanetNeuroIncentivesPool(
address(h),
isNativeReward ? address(0) : h.getContractAddress(incentivesPoolType),
h.getContractAddress("ParanetsRegistry"),
h.getContractAddress("ParanetKnowledgeMinersRegistry"),
keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)),
Expand All @@ -84,14 +87,14 @@ contract ParanetIncentivesPoolFactory is Named, Versioned, ContractStatusV2, Ini

pr.setIncentivesPoolAddress(
keccak256(abi.encodePacked(paranetKAStorageContract, paranetKATokenId)),
"Neuroweb",
incentivesPoolType,
address(incentivesPool)
);

emit ParanetIncetivesPoolDeployed(
paranetKAStorageContract,
paranetKATokenId,
ParanetStructs.IncentivesPool({poolType: "Neuroweb", addr: address(incentivesPool)})
ParanetStructs.IncentivesPool({poolType: incentivesPoolType, addr: address(incentivesPool)})
);

return address(incentivesPool);
Expand Down
63 changes: 51 additions & 12 deletions contracts/v2/paranets/ParanetNeuroIncentivesPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,29 @@ import {Named} from "../../v1/interface/Named.sol";
import {Versioned} from "../../v1/interface/Versioned.sol";
import {ParanetErrors} from "../errors/paranets/ParanetErrors.sol";
import {ParanetStructs} from "../structs/paranets/ParanetStructs.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {
EMISSION_MULTIPLIER_SCALING_FACTOR,
PERCENTAGE_SCALING_FACTOR,
TOKENS_DIGITS_DIFF,
NATIVE_NEURO_DECIMALS_DIFF,
MAX_CUMULATIVE_VOTERS_WEIGHT
} from "../constants/ParanetIncentivesPoolConstants.sol";

contract ParanetNeuroIncentivesPool is Named, Versioned {
event NeuroRewardDeposit(address indexed sender, uint256 amount);
event NativeNeuroRewardDeposit(address indexed sender, uint256 amount);
event NeuroEmissionMultiplierUpdateInitiated(uint256 oldMultiplier, uint256 newMultiplier, uint256 timestamp);
event NeuroEmissionMultiplierUpdateFinalized(uint256 oldMultiplier, uint256 newMultiplier);
event ParanetKnowledgeMinerRewardClaimed(address indexed miner, uint256 amount);
event ParanetOperatorRewardClaimed(address indexed operator, uint256 amount);
event ParanetIncentivizationProposalVoterRewardClaimed(address indexed voter, uint256 amount);

string private constant _NAME = "ParanetNeuroIncentivesPool";
string private constant _VERSION = "2.1.3";
string private constant _VERSION = "2.2.0";

HubV2 public hub;
IERC20 public token;
ParanetsRegistry public paranetsRegistry;
ParanetKnowledgeMinersRegistry public paranetKnowledgeMinersRegistry;

Expand Down Expand Up @@ -73,6 +75,7 @@ contract ParanetNeuroIncentivesPool is Named, Versioned {
// solhint-disable-next-line no-empty-blocks
constructor(
address hubAddress,
address rewardTokenAddress,
address paranetsRegistryAddress,
address knowledgeMinersRegistryAddress,
bytes32 paranetId,
Expand All @@ -87,6 +90,9 @@ contract ParanetNeuroIncentivesPool is Named, Versioned {
);

hub = HubV2(hubAddress);
if (rewardTokenAddress != address(0)) {
token = IERC20(rewardTokenAddress);
}
paranetsRegistry = ParanetsRegistry(paranetsRegistryAddress);
paranetKnowledgeMinersRegistry = ParanetKnowledgeMinersRegistry(knowledgeMinersRegistryAddress);

Expand Down Expand Up @@ -147,15 +153,33 @@ contract ParanetNeuroIncentivesPool is Named, Versioned {
}

receive() external payable {
emit NeuroRewardDeposit(msg.sender, msg.value);
emit NativeNeuroRewardDeposit(msg.sender, msg.value);
}

function isNativeNeuro() public view returns (bool) {
return address(token) == address(0);
}

function totalNeuroReceived() external view returns (uint256) {
return address(this).balance + totalMinersClaimedNeuro + totalOperatorsClaimedNeuro + totalVotersClaimedNeuro;
if (isNativeNeuro()) {
return (address(this).balance +
totalMinersClaimedNeuro +
totalOperatorsClaimedNeuro +
totalVotersClaimedNeuro);
} else {
return (token.balanceOf(address(this)) +
totalMinersClaimedNeuro +
totalOperatorsClaimedNeuro +
totalVotersClaimedNeuro);
}
}

function getNeuroBalance() external view returns (uint256) {
return address(this).balance;
if (isNativeNeuro()) {
return address(this).balance;
} else {
return token.balanceOf(address(this));
}
}

function updateNeuroEmissionMultiplierUpdateDelay(uint256 newDelay) external onlyHubOwner {
Expand Down Expand Up @@ -320,7 +344,7 @@ contract ParanetNeuroIncentivesPool is Named, Versioned {
function getTotalKnowledgeMinerIncentiveEstimation() public view returns (uint256) {
uint96 unrewardedTracSpent = paranetKnowledgeMinersRegistry.getUnrewardedTracSpent(msg.sender, parentParanetId);

if (unrewardedTracSpent < TOKENS_DIGITS_DIFF) {
if (isNativeNeuro() && unrewardedTracSpent < NATIVE_NEURO_DECIMALS_DIFF) {
return 0;
}

Expand Down Expand Up @@ -442,7 +466,11 @@ contract ParanetNeuroIncentivesPool is Named, Versioned {
}
totalMinersClaimedNeuro += claimableNeuroReward;

payable(msg.sender).transfer(claimableNeuroReward);
if (isNativeNeuro()) {
payable(msg.sender).transfer(claimableNeuroReward);
} else {
token.transfer(msg.sender, claimableNeuroReward);
}

emit ParanetKnowledgeMinerRewardClaimed(msg.sender, claimableNeuroReward);
}
Expand Down Expand Up @@ -488,7 +516,11 @@ contract ParanetNeuroIncentivesPool is Named, Versioned {
}
totalOperatorsClaimedNeuro += claimableNeuroReward;

payable(msg.sender).transfer(claimableNeuroReward);
if (isNativeNeuro()) {
payable(msg.sender).transfer(claimableNeuroReward);
} else {
token.transfer(msg.sender, claimableNeuroReward);
}

emit ParanetOperatorRewardClaimed(msg.sender, claimableNeuroReward);
}
Expand All @@ -504,7 +536,10 @@ contract ParanetNeuroIncentivesPool is Named, Versioned {
effectiveNeuroEmissionMultiplier
);

if (cumulativeKnowledgeValueSingleVoterPart - rewardedTracSpentSingleVoterPart < TOKENS_DIGITS_DIFF) {
if (
isNativeNeuro() &&
(cumulativeKnowledgeValueSingleVoterPart - rewardedTracSpentSingleVoterPart < NATIVE_NEURO_DECIMALS_DIFF)
) {
return 0;
}

Expand Down Expand Up @@ -569,7 +604,11 @@ contract ParanetNeuroIncentivesPool is Named, Versioned {
voters[votersIndexes[msg.sender]].claimedNeuro += claimableNeuroReward;
totalVotersClaimedNeuro += claimableNeuroReward;

payable(msg.sender).transfer(claimableNeuroReward);
if (isNativeNeuro()) {
payable(msg.sender).transfer(claimableNeuroReward);
} else {
token.transfer(msg.sender, claimableNeuroReward);
}

emit ParanetIncentivizationProposalVoterRewardClaimed(msg.sender, claimableNeuroReward);
}
Expand All @@ -585,7 +624,7 @@ contract ParanetNeuroIncentivesPool is Named, Versioned {
(totalClaimedNeuro * EMISSION_MULTIPLIER_SCALING_FACTOR) / effectiveNeuroEmissionMultiplier
);

if (cumulativeKnowledgeValuePart - rewardedTracSpentPart < TOKENS_DIGITS_DIFF) {
if (isNativeNeuro() && (cumulativeKnowledgeValuePart - rewardedTracSpentPart < NATIVE_NEURO_DECIMALS_DIFF)) {
return 0;
}

Expand Down
26 changes: 26 additions & 0 deletions deploy/100_set_neuroweb_erc20.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();

const neuroERC20Exists = hre.helpers.inConfig('NeurowebERC20');

if (neuroERC20Exists) {
const hubAddress = hre.helpers.contractDeployments.contracts['Hub'].evmAddress;
const Hub = await hre.ethers.getContractAt('Hub', hubAddress, deployer);

const tokenInHub = await Hub['isContract(string)']('NeurowebERC20');

if (!tokenInHub) {
hre.helpers.newContracts.push([
'NeurowebERC20',
hre.helpers.contractDeployments.contracts['NeurowebERC20'].evmAddress,
]);
}
}
};

export default func;
func.tags = ['Neuro', 'v1'];
func.dependencies = ['Hub'];
4 changes: 4 additions & 0 deletions deployments/base_mainnet_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"deployed": true,
"evmAddress": "0xa81a52b4dda010896cdd386c7fbdc5cdc835ba23"
},
"NeurowebERC20": {
"deployed": true,
"evmAddress": "0x2548c27A04e49B412DD887b08d062D34C72ad2B6"
},
"Hub": {
"evmAddress": "0xaBfcf2ad1718828E7D3ec20435b0d0b5EAfbDf2c",
"version": "2.0.0",
Expand Down
Loading
Loading