Skip to content
Open
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
86 changes: 86 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
module.exports = {
env: {
node: true,
es2021: true
},
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/recommended'
],
parserOptions: {
ecmaVersion: 13,
requireConfigFile: false
},
plugins: [
'@typescript-eslint',
'prefer-arrow'
],
ignorePatterns: [
'node_modules'
],
rules: {
'curly': ['error', 'multi-line'],
'no-implicit-coercion': ['error'],
'indent': ['error', 4, {
SwitchCase: 1,
MemberExpression: 1,
ArrayExpression: 1,
ObjectExpression: 1,
VariableDeclarator: 1,
CallExpression: {arguments: 1},
offsetTernaryExpressions: true
}],
'semi': ['error', 'always'],
'linebreak-style': ['error', 'unix'],
'no-fallthrough': 'off',
'no-console': 'off',
'no-debugger': 'error',
'max-len': ['warn', {
code: 100,
ignoreStrings: true,
ignoreRegExpLiterals: true,
ignoreTemplateLiterals: true,
tabWidth: 4,
ignoreComments: true
}],
'comma-dangle': ['error', 'never'],
'space-in-parens': ['error', 'never'],
'comma-spacing': 'error',
'object-curly-spacing': ['error', 'never'],
'object-curly-newline': ['error', {multiline: true}],
'array-bracket-spacing': ['error', 'never'],
'eqeqeq': ['error', 'always', {null: 'ignore'}],
'no-useless-call': 'error',
'prefer-promise-reject-errors': 'error',
'no-underscore-dangle': 'error',
'prefer-const': ['error', {destructuring: 'all', ignoreReadBeforeAssign: false}],
'no-bitwise': 'off',
'no-caller': 'error',
'no-useless-return': 'error',
'no-duplicate-imports': 'error',
'no-unused-expressions': 'error',
'arrow-body-style': ['error', 'as-needed'],
'prefer-arrow/prefer-arrow-functions': ['error', {
disallowPrototype: true,
singleReturnOnly: false,
classPropertiesAllowed: false
}],
'brace-style': ['error', '1tbs', {allowSingleLine: true}],
'space-infix-ops': ['error'],
'quote-props': ['error', 'consistent-as-needed'],
'no-multiple-empty-lines': ['warn', {max: 1, maxEOF: 0}],
'quotes': ['error', 'single', {allowTemplateLiterals: true}],
'no-eval': 'error',
'no-implied-eval': 'error',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-this-alias': 'error',
'@typescript-eslint/no-empty-function': 'error',
'no-shadow': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/keyword-spacing': ['error']
}
};
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,12 @@ dist

# TernJS port file
.tern-port

node_modules
coverage.json
typechain
typechain-types

#Hardhat files
cache
artifacts
10 changes: 10 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
semi: true,
trailingComma: 'none',
singleQuote: true,
printWidth: 100,
tabWidth: 4,
useTabs: false,
bracketSpacing: false,
arrowParens: 'avoid'
};
9 changes: 9 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "solhint:recommended",
"plugins": [],
"rules": {
"avoid-suicide": "error",
"avoid-sha3": "warn",
"compiler-version": ["error", "^0.8.0"]
}
}
71 changes: 71 additions & 0 deletions contracts/Subscriptions.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract Subscriptions is Initializable, UUPSUpgradeable, OwnableUpgradeable {
using Counters for Counters.Counter;
Counters.Counter internal _subscriptionIds;

struct Subscription {
address contractAddress;
string[] topics;
}

mapping (address => uint256[]) public subscriptionsIdsByUser;
mapping (uint256 => Subscription) public subscriptionsById;
mapping (address => uint256) public blockNumbersByUser;

function initialize() public initializer onlyProxy {
__Ownable_init();
__UUPSUpgradeable_init();
}

function _authorizeUpgrade(address) internal override onlyOwner {}

function subscribe(
address contractAddress,
string[] calldata topics
) public {
require(topics.length > 0, "Event filter should have at least 1 topic");
require(topics.length <= 4, "Event filter cannot have more than 4 topics");

_subscriptionIds.increment();
uint256 newSubscriptionId = _subscriptionIds.current();

subscriptionsIdsByUser[msg.sender].push(newSubscriptionId);
subscriptionsById[newSubscriptionId] = Subscription(contractAddress, topics);
blockNumbersByUser[msg.sender] = block.timestamp;
}

function unsubscribe(uint256 index) public {
uint256 userSubscriptionsLength = subscriptionsIdsByUser[msg.sender].length;

require(index < userSubscriptionsLength, "Non-existent subscription index");

subscriptionsIdsByUser[msg.sender][index] = subscriptionsIdsByUser[msg.sender][userSubscriptionsLength - 1];
subscriptionsIdsByUser[msg.sender].pop();
}

function updateBlockTimeStamp() public {
blockNumbersByUser[msg.sender] = block.timestamp;
}

function getSubscriptionsByUser(address userAddress)
public
view
returns (Subscription[] memory)
{
uint256 userSubscriptionsLength = subscriptionsIdsByUser[userAddress].length;

Subscription[] memory userSubscriptions = new Subscription[](userSubscriptionsLength);
for (uint i = 0; i < userSubscriptionsLength; i++) {
userSubscriptions[i] = subscriptionsById[subscriptionsIdsByUser[userAddress][i]];
}

return userSubscriptions;
}
}
84 changes: 84 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import dotenv from 'dotenv';
import os from 'os';
import path from 'path';
import {hdkey} from 'ethereumjs-wallet';
import {mnemonicToSeedSync} from 'bip39';
import fs from 'fs';
import {HardhatUserConfig} from 'hardhat/config';
import '@openzeppelin/hardhat-upgrades';
import './tasks/deploy';

dotenv.config();

let privateKey = process.env.DEPLOYER_ACCOUNT;

try {
if (privateKey === undefined) {
const homedir = os.homedir();
const wallet = hdkey.fromMasterSeed(
mnemonicToSeedSync(
JSON.parse(fs.readFileSync(path.resolve(
homedir,
'.point',
'keystore',
'key.json'
), 'utf8')).phrase
)
).getWallet();
privateKey = wallet.getPrivateKey().toString('hex');
}
} catch (e) {
if (!privateKey) {
console.log(
'Warn: Private key not found. Will not be possible to deploy.'
);
}
}

const config: HardhatUserConfig = {
solidity: {
compilers: [
{
version: '0.8.0',
settings: {
optimizer: {
enabled: true,
runs: 1000
}
}
},
{
version: '0.8.4',
settings: {
optimizer: {
enabled: true,
runs: 1000
}
}
},
{
version: '0.8.7',
settings: {
optimizer: {
enabled: true,
runs: 1000
}
}
}
]
},
networks: {
xnetUranus: {
accounts: [privateKey!],
url: 'https://xnet-uranus-1.point.space/',
gasPrice: 7
},
mainnet: {
accounts: [privateKey!],
url: 'https://rpc-mainnet-1.point.space',
gasPrice: 7
}
}
};

export default config;
Loading