From 18dbaaeaedd52a5f7052413de837adff038f8ada Mon Sep 17 00:00:00 2001 From: nya-elimu Date: Mon, 5 Aug 2024 12:10:50 +0700 Subject: [PATCH 01/10] feat(distribution): npx tsc --init #45 --- DRIP_LIST_FUNDING_SPLITS.md | 4 +- funding-splits/distribution/.gitignore | 1 + funding-splits/distribution/README.md | 11 ++ funding-splits/distribution/package-lock.json | 29 +++++ funding-splits/distribution/package.json | 14 +++ funding-splits/distribution/tsconfig.json | 108 ++++++++++++++++++ 6 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 funding-splits/distribution/.gitignore create mode 100644 funding-splits/distribution/README.md create mode 100644 funding-splits/distribution/package-lock.json create mode 100644 funding-splits/distribution/package.json create mode 100644 funding-splits/distribution/tsconfig.json diff --git a/DRIP_LIST_FUNDING_SPLITS.md b/DRIP_LIST_FUNDING_SPLITS.md index 830b126..6f05c1d 100644 --- a/DRIP_LIST_FUNDING_SPLITS.md +++ b/DRIP_LIST_FUNDING_SPLITS.md @@ -117,8 +117,8 @@ distribution.elimu.eth,tgl.distribution.elimu.eth,10 | [start-guide](https://github.com/elimu-ai/start-guide) | `distribution.elimu.eth` | | | [website](https://github.com/elimu-ai/website) | `distribution.elimu.eth` | [`FUNDING_SPLITS.csv`](https://github.com/elimu-ai/website/blob/main/FUNDING_SPLITS.csv) | | [web3-sponsors](https://github.com/elimu-ai/web3-sponsors) | `distribution.elimu.eth` | | -| Hindi Language 🏏🐯 | `hin.distribution.elimu.eth` | | -| Tagalog Language 🏝️🦎 | `tgl.distribution.elimu.eth` | | +| Hindi Language 🏏🐯 | `hin.distribution.elimu.eth` | [`FUNDING_SPLITS_HIN.csv`](./funding-splits/distribution/FUNDING_SPLITS_HIN.csv) | +| Tagalog Language 🏝️🦎 | `tgl.distribution.elimu.eth` | [`FUNDING_SPLITS_TGL.csv`](./funding-splits/distribution/FUNDING_SPLITS_TGL.csv) | --- diff --git a/funding-splits/distribution/.gitignore b/funding-splits/distribution/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/funding-splits/distribution/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/funding-splits/distribution/README.md b/funding-splits/distribution/README.md new file mode 100644 index 0000000..8b607e9 --- /dev/null +++ b/funding-splits/distribution/README.md @@ -0,0 +1,11 @@ +# distribution + +> Drip List funding splits for Distribution & Data Collection πŸ›΅πŸ’¨ + +See [`../../DRIP_LIST_FUNDING_SPLITS.md#distribution`](../../DRIP_LIST_FUNDING_SPLITS.md#distribution) + +## Run the TypeScript Compiler + +```bash +npx tsc +``` diff --git a/funding-splits/distribution/package-lock.json b/funding-splits/distribution/package-lock.json new file mode 100644 index 0000000..526fb6c --- /dev/null +++ b/funding-splits/distribution/package-lock.json @@ -0,0 +1,29 @@ +{ + "name": "distribution", + "version": "0.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "distribution", + "version": "0.0.1", + "license": "MIT", + "devDependencies": { + "typescript": "^5.5.4" + } + }, + "node_modules/typescript": { + "version": "5.5.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", + "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + } +} diff --git a/funding-splits/distribution/package.json b/funding-splits/distribution/package.json new file mode 100644 index 0000000..87402de --- /dev/null +++ b/funding-splits/distribution/package.json @@ -0,0 +1,14 @@ +{ + "name": "distribution", + "version": "0.0.1", + "description": "Drip List funding splits for Distribution & Data Collection πŸ›΅πŸ’¨", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Ξlimu DAO", + "license": "MIT", + "devDependencies": { + "typescript": "^5.5.4" + } +} diff --git a/funding-splits/distribution/tsconfig.json b/funding-splits/distribution/tsconfig.json new file mode 100644 index 0000000..8bb6097 --- /dev/null +++ b/funding-splits/distribution/tsconfig.json @@ -0,0 +1,108 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + + /* Modules */ + "module": "commonjs", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ + // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ + // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + // "outDir": "./", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +} From 2922f2e429f95cf6ee26332d213957037f35c0d4 Mon Sep 17 00:00:00 2001 From: nya-elimu Date: Mon, 5 Aug 2024 12:41:28 +0700 Subject: [PATCH 02/10] feat(distribution): fetch sponsorship events #45 --- funding-splits/distribution/README.md | 12 ++++++++++++ .../distribution/fetch-sponsorship-events.js | 3 +++ .../distribution/fetch-sponsorship-events.ts | 2 ++ 3 files changed, 17 insertions(+) create mode 100644 funding-splits/distribution/fetch-sponsorship-events.js create mode 100644 funding-splits/distribution/fetch-sponsorship-events.ts diff --git a/funding-splits/distribution/README.md b/funding-splits/distribution/README.md index 8b607e9..5a0e972 100644 --- a/funding-splits/distribution/README.md +++ b/funding-splits/distribution/README.md @@ -4,8 +4,20 @@ See [`../../DRIP_LIST_FUNDING_SPLITS.md#distribution`](../../DRIP_LIST_FUNDING_SPLITS.md#distribution) +## Install Dependencies + +```bash +npm install +``` + ## Run the TypeScript Compiler ```bash npx tsc ``` + +## Run the JavaScript + +```bash +node ./fetch-sponsorship-events.js +``` diff --git a/funding-splits/distribution/fetch-sponsorship-events.js b/funding-splits/distribution/fetch-sponsorship-events.js new file mode 100644 index 0000000..bfe07e2 --- /dev/null +++ b/funding-splits/distribution/fetch-sponsorship-events.js @@ -0,0 +1,3 @@ +"use strict"; +let helloWorld = "Hello World"; +console.log('helloWorld:', helloWorld); diff --git a/funding-splits/distribution/fetch-sponsorship-events.ts b/funding-splits/distribution/fetch-sponsorship-events.ts new file mode 100644 index 0000000..33f2f81 --- /dev/null +++ b/funding-splits/distribution/fetch-sponsorship-events.ts @@ -0,0 +1,2 @@ +let helloWorld = "Hello World" +console.log('helloWorld:', helloWorld) From a19fd58323aab6aa8acee9b6d5ae6501250300eb Mon Sep 17 00:00:00 2001 From: nya-elimu Date: Mon, 5 Aug 2024 12:43:51 +0700 Subject: [PATCH 03/10] feat(distribution): fetch sponsorship events #45 --- .github/workflows/node.js.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/node.js.yml diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000..58af9c7 --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,35 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs + +name: Node.js CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x, 20.x, 22.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + defaults: + run: + working-directory: frontend + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + cache-dependency-path: frontend/package-lock.json + - run: npm ci + - run: npx tsc From 24126e2b6b971d65f338125f367d7dde17e796ef Mon Sep 17 00:00:00 2001 From: nya-elimu Date: Mon, 5 Aug 2024 12:45:58 +0700 Subject: [PATCH 04/10] feat(distribution): fetch sponsorship events #45 --- .github/workflows/node.js.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 58af9c7..5d6d487 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -21,7 +21,7 @@ jobs: defaults: run: - working-directory: frontend + working-directory: funding-splits/distribution steps: - uses: actions/checkout@v4 @@ -30,6 +30,6 @@ jobs: with: node-version: ${{ matrix.node-version }} cache: 'npm' - cache-dependency-path: frontend/package-lock.json + cache-dependency-path: funding-splits/distribution/package-lock.json - run: npm ci - run: npx tsc From e2662dc039ca8feb4037db477fe98eacabff9cab Mon Sep 17 00:00:00 2001 From: nya-elimu Date: Mon, 5 Aug 2024 14:32:47 +0700 Subject: [PATCH 05/10] feat(distribution): fetch sponsorship events #45 --- funding-splits/distribution/README.md | 2 +- .../distribution/abis/SponsorshipQueue.json | 177 ++++++++++++++++++ .../distribution/fetch-sponsorship-events.js | 3 - .../distribution/fetch-sponsorship-events.ts | 2 - funding-splits/distribution/package-lock.json | 98 ++++++++++ funding-splits/distribution/package.json | 1 + .../distribution/query-sponsorship-events.js | 36 ++++ .../distribution/query-sponsorship-events.ts | 31 +++ funding-splits/distribution/tsconfig.json | 2 +- 9 files changed, 345 insertions(+), 7 deletions(-) create mode 100644 funding-splits/distribution/abis/SponsorshipQueue.json delete mode 100644 funding-splits/distribution/fetch-sponsorship-events.js delete mode 100644 funding-splits/distribution/fetch-sponsorship-events.ts create mode 100644 funding-splits/distribution/query-sponsorship-events.js create mode 100644 funding-splits/distribution/query-sponsorship-events.ts diff --git a/funding-splits/distribution/README.md b/funding-splits/distribution/README.md index 5a0e972..de07075 100644 --- a/funding-splits/distribution/README.md +++ b/funding-splits/distribution/README.md @@ -19,5 +19,5 @@ npx tsc ## Run the JavaScript ```bash -node ./fetch-sponsorship-events.js +node ./query-sponsorship-events.js ``` diff --git a/funding-splits/distribution/abis/SponsorshipQueue.json b/funding-splits/distribution/abis/SponsorshipQueue.json new file mode 100644 index 0000000..1ea90cc --- /dev/null +++ b/funding-splits/distribution/abis/SponsorshipQueue.json @@ -0,0 +1,177 @@ +{ + "abi": [ + { + "inputs": [ + { + "internalType": "uint256", + "name": "_estimatedCost", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "OnlyOwner", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "estimatedCost", + "type": "uint256" + } + ], + "name": "EstimatedCostUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "OwnerUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "estimatedCost", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "internalType": "address", + "name": "sponsor", + "type": "address" + } + ], + "indexed": false, + "internalType": "struct Sponsorship", + "name": "sponsorship", + "type": "tuple" + } + ], + "name": "SponsorshipAdded", + "type": "event" + }, + { + "inputs": [], + "name": "addSponsorship", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "estimatedCost", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getQueueCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "queue", + "outputs": [ + { + "internalType": "uint256", + "name": "estimatedCost", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "internalType": "address", + "name": "sponsor", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_estimatedCost", + "type": "uint256" + } + ], + "name": "updateEstimatedCost", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_owner", + "type": "address" + } + ], + "name": "updateOwner", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ] +} diff --git a/funding-splits/distribution/fetch-sponsorship-events.js b/funding-splits/distribution/fetch-sponsorship-events.js deleted file mode 100644 index bfe07e2..0000000 --- a/funding-splits/distribution/fetch-sponsorship-events.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -let helloWorld = "Hello World"; -console.log('helloWorld:', helloWorld); diff --git a/funding-splits/distribution/fetch-sponsorship-events.ts b/funding-splits/distribution/fetch-sponsorship-events.ts deleted file mode 100644 index 33f2f81..0000000 --- a/funding-splits/distribution/fetch-sponsorship-events.ts +++ /dev/null @@ -1,2 +0,0 @@ -let helloWorld = "Hello World" -console.log('helloWorld:', helloWorld) diff --git a/funding-splits/distribution/package-lock.json b/funding-splits/distribution/package-lock.json index 526fb6c..651a7db 100644 --- a/funding-splits/distribution/package-lock.json +++ b/funding-splits/distribution/package-lock.json @@ -9,9 +9,86 @@ "version": "0.0.1", "license": "MIT", "devDependencies": { + "ethers": "^6.13.2", "typescript": "^5.5.4" } }, + "node_modules/@adraffy/ens-normalize": { + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.10.1.tgz", + "integrity": "sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw==", + "dev": true + }, + "node_modules/@noble/curves": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.2.0.tgz", + "integrity": "sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==", + "dev": true, + "dependencies": { + "@noble/hashes": "1.3.2" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/hashes": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", + "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", + "dev": true, + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@types/node": { + "version": "18.15.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.13.tgz", + "integrity": "sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q==", + "dev": true + }, + "node_modules/aes-js": { + "version": "4.0.0-beta.5", + "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-4.0.0-beta.5.tgz", + "integrity": "sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==", + "dev": true + }, + "node_modules/ethers": { + "version": "6.13.2", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.13.2.tgz", + "integrity": "sha512-9VkriTTed+/27BGuY1s0hf441kqwHJ1wtN2edksEtiRvXx+soxRX3iSXTfFqq2+YwrOqbDoTHjIhQnjJRlzKmg==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/ethers-io/" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@adraffy/ens-normalize": "1.10.1", + "@noble/curves": "1.2.0", + "@noble/hashes": "1.3.2", + "@types/node": "18.15.13", + "aes-js": "4.0.0-beta.5", + "tslib": "2.4.0", + "ws": "8.17.1" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==", + "dev": true + }, "node_modules/typescript": { "version": "5.5.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", @@ -24,6 +101,27 @@ "engines": { "node": ">=14.17" } + }, + "node_modules/ws": { + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", + "dev": true, + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } } } } diff --git a/funding-splits/distribution/package.json b/funding-splits/distribution/package.json index 87402de..fd02ab6 100644 --- a/funding-splits/distribution/package.json +++ b/funding-splits/distribution/package.json @@ -9,6 +9,7 @@ "author": "Ξlimu DAO", "license": "MIT", "devDependencies": { + "ethers": "^6.13.2", "typescript": "^5.5.4" } } diff --git a/funding-splits/distribution/query-sponsorship-events.js b/funding-splits/distribution/query-sponsorship-events.js new file mode 100644 index 0000000..2aa8491 --- /dev/null +++ b/funding-splits/distribution/query-sponsorship-events.js @@ -0,0 +1,36 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const ethers_1 = require("ethers"); +const SponsorshipQueue_json_1 = __importDefault(require("./abis/SponsorshipQueue.json")); +const rpcServerAddress = 'https://base-sepolia.blockpi.network/v1/rpc/public'; +console.log('rpcServerAddress:', rpcServerAddress); +const provider = new ethers_1.ethers.JsonRpcProvider(rpcServerAddress); +// console.log('provider:', provider) +const sponsorshipQueueContract = new ethers_1.ethers.Contract('0x9Af2E73663968fdfb9791b7D6Bd40cd259f0388a', SponsorshipQueue_json_1.default.abi, provider); +// console.log('sponsorshipQueueContract:', sponsorshipQueueContract) +function query() { + return __awaiter(this, void 0, void 0, function* () { + console.log('query'); + const events = yield sponsorshipQueueContract.queryFilter('*'); + console.log('events.length:', events.length); + events.forEach((eventLog) => { + console.log('\n'); + console.log('eventLog.blockNumber:', eventLog.blockNumber); + console.log('eventLog.fragment.name:', eventLog.fragment.name); + console.log('eventLog.args:', eventLog.args); + }); + }); +} +query(); diff --git a/funding-splits/distribution/query-sponsorship-events.ts b/funding-splits/distribution/query-sponsorship-events.ts new file mode 100644 index 0000000..abdd9f4 --- /dev/null +++ b/funding-splits/distribution/query-sponsorship-events.ts @@ -0,0 +1,31 @@ +import { Contract, ethers, EventLog, JsonRpcProvider, Log } from 'ethers' +import SponsorshipQueue from './abis/SponsorshipQueue.json' + +const rpcServerAddress: string = 'https://base-sepolia.blockpi.network/v1/rpc/public' +console.log('rpcServerAddress:', rpcServerAddress) + +const provider: JsonRpcProvider = new ethers.JsonRpcProvider(rpcServerAddress) +// console.log('provider:', provider) + +const sponsorshipQueueContract: Contract = new ethers.Contract( + '0x9Af2E73663968fdfb9791b7D6Bd40cd259f0388a', + SponsorshipQueue.abi, + provider +) +// console.log('sponsorshipQueueContract:', sponsorshipQueueContract) + +async function query() { + console.log('query') + + const events = await sponsorshipQueueContract.queryFilter('*') + console.log('events.length:', events.length) + + events.forEach((eventLog: any) => { + console.log('\n') + console.log('eventLog.blockNumber:', eventLog.blockNumber) + console.log('eventLog.fragment.name:', eventLog.fragment.name) + console.log('eventLog.args:', eventLog.args) + }) +} + +query() diff --git a/funding-splits/distribution/tsconfig.json b/funding-splits/distribution/tsconfig.json index 8bb6097..958e7cd 100644 --- a/funding-splits/distribution/tsconfig.json +++ b/funding-splits/distribution/tsconfig.json @@ -39,7 +39,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ - // "resolveJsonModule": true, /* Enable importing .json files. */ + "resolveJsonModule": true, /* Enable importing .json files. */ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ From e2f4915c007ad955f744fd3e5fd4e3787f006080 Mon Sep 17 00:00:00 2001 From: nya-elimu Date: Mon, 5 Aug 2024 15:52:57 +0700 Subject: [PATCH 06/10] feat(distribution): add/update csv data #45 --- .../distribution/query-sponsorship-events.js | 85 ++++++++++++++- .../distribution/query-sponsorship-events.ts | 102 ++++++++++++++++-- 2 files changed, 176 insertions(+), 11 deletions(-) diff --git a/funding-splits/distribution/query-sponsorship-events.js b/funding-splits/distribution/query-sponsorship-events.js index 2aa8491..f9b96e6 100644 --- a/funding-splits/distribution/query-sponsorship-events.js +++ b/funding-splits/distribution/query-sponsorship-events.js @@ -20,17 +20,92 @@ const provider = new ethers_1.ethers.JsonRpcProvider(rpcServerAddress); // console.log('provider:', provider) const sponsorshipQueueContract = new ethers_1.ethers.Contract('0x9Af2E73663968fdfb9791b7D6Bd40cd259f0388a', SponsorshipQueue_json_1.default.abi, provider); // console.log('sponsorshipQueueContract:', sponsorshipQueueContract) +query(); function query() { return __awaiter(this, void 0, void 0, function* () { console.log('query'); const events = yield sponsorshipQueueContract.queryFilter('*'); console.log('events.length:', events.length); + const eventData = []; events.forEach((eventLog) => { - console.log('\n'); - console.log('eventLog.blockNumber:', eventLog.blockNumber); - console.log('eventLog.fragment.name:', eventLog.fragment.name); - console.log('eventLog.args:', eventLog.args); + console.log(''); + // console.log('eventLog:', eventLog) + const blockNumber = eventLog.blockNumber; + console.log('blockNumber:', eventLog.blockNumber); + const eventName = eventLog.fragment.name; + console.log('eventName:', eventName); + const argResult = eventLog.args; + // console.log('argResult:', argResult) + // + // Sample: + // + // Result(1) [ + // Result(3) [ + // 2000000000000000n, + // 1721578316n, + // '0x015B5dF1673499E32D11Cf786A43D1c42b3d725C' + // ] + // ] + if (eventName == 'SponsorshipAdded') { + const argResultArray = argResult[0]; + // console.log('argResultArray:', argResultArray) + const estimatedCost = argResultArray[0]; + console.log('estimatedCost:', estimatedCost); + const timestamp = argResultArray[1]; + console.log('timestamp:', timestamp); + const sponsorAddress = argResultArray[2]; + console.log('sponsorAddress:', sponsorAddress); + eventData.push([estimatedCost, timestamp, sponsorAddress]); + } }); + exportToCsv(eventData); + }); +} +function exportToCsv(eventData) { + return __awaiter(this, void 0, void 0, function* () { + console.log('exportToCsv'); + console.log('eventData.length:', eventData.length); + // Count events per sponsor address + const csvData = []; + // Sample: + // + // [ + // { + // ethereum_address: '0x015B5dF1673499E32D11Cf786A43D1c42b3d725C' + // sponsorship_count: 1 + // distribution_count: 0 + // impact_percentage: 100 + // } + // ] + eventData.forEach(sponsorshipEvent => { + const estimatedCost = sponsorshipEvent[0]; + const timestamp = sponsorshipEvent[1]; + const sponsorAddress = sponsorshipEvent[2]; + // Check if data already exists for the sponsor address + let existingData = undefined; + csvData.forEach(data => { + // console.log('data:', data) + if (sponsorAddress == data.ethereum_address) { + existingData = data; + } + }); + if (!existingData) { + console.log('Add data for address:', sponsorAddress); + const newData = { + ethereum_address: sponsorAddress, + sponsorship_count: 1, + distribution_count: 0, + impact_percentage: 0 // TODO + }; + csvData.push(newData); + } + else { + console.log('Update data for address:', sponsorAddress); + existingData.sponsorship_count++; + } + }); + console.log('csvData:\n', csvData); + // Export to CSV + // TODO }); } -query(); diff --git a/funding-splits/distribution/query-sponsorship-events.ts b/funding-splits/distribution/query-sponsorship-events.ts index abdd9f4..0711f5e 100644 --- a/funding-splits/distribution/query-sponsorship-events.ts +++ b/funding-splits/distribution/query-sponsorship-events.ts @@ -1,4 +1,4 @@ -import { Contract, ethers, EventLog, JsonRpcProvider, Log } from 'ethers' +import { Contract, ethers, EventLog, JsonRpcProvider, Log, Result } from 'ethers' import SponsorshipQueue from './abis/SponsorshipQueue.json' const rpcServerAddress: string = 'https://base-sepolia.blockpi.network/v1/rpc/public' @@ -14,18 +14,108 @@ const sponsorshipQueueContract: Contract = new ethers.Contract( ) // console.log('sponsorshipQueueContract:', sponsorshipQueueContract) +query() + async function query() { console.log('query') const events = await sponsorshipQueueContract.queryFilter('*') console.log('events.length:', events.length) + const eventData: any[] = [] + events.forEach((eventLog: any) => { - console.log('\n') - console.log('eventLog.blockNumber:', eventLog.blockNumber) - console.log('eventLog.fragment.name:', eventLog.fragment.name) - console.log('eventLog.args:', eventLog.args) + console.log('') + // console.log('eventLog:', eventLog) + + const blockNumber: number = eventLog.blockNumber + console.log('blockNumber:', eventLog.blockNumber) + + const eventName: string = eventLog.fragment.name + console.log('eventName:', eventName) + + const argResult: Result = eventLog.args + // console.log('argResult:', argResult) + // + // Sample: + // + // Result(1) [ + // Result(3) [ + // 2000000000000000n, + // 1721578316n, + // '0x015B5dF1673499E32D11Cf786A43D1c42b3d725C' + // ] + // ] + + if (eventName == 'SponsorshipAdded') { + const argResultArray: Result = argResult[0] + // console.log('argResultArray:', argResultArray) + + const estimatedCost: number = argResultArray[0] + console.log('estimatedCost:', estimatedCost) + + const timestamp: number = argResultArray[1] + console.log('timestamp:', timestamp) + + const sponsorAddress: string = argResultArray[2] + console.log('sponsorAddress:', sponsorAddress) + + eventData.push([estimatedCost, timestamp, sponsorAddress]) + } }) + + exportToCsv(eventData) } -query() +async function exportToCsv(eventData: any[]) { + console.log('exportToCsv') + + console.log('eventData.length:', eventData.length) + + // Count events per sponsor address + const csvData: any[] = [] + // Sample: + // + // [ + // { + // ethereum_address: '0x015B5dF1673499E32D11Cf786A43D1c42b3d725C' + // sponsorship_count: 1 + // distribution_count: 0 + // impact_percentage: 100 + // } + // ] + eventData.forEach(sponsorshipEvent => { + const estimatedCost: number = sponsorshipEvent[0] + const timestamp: number = sponsorshipEvent[1] + const sponsorAddress: string = sponsorshipEvent[2] + + // Check if data already exists for the sponsor address + let existingData: any = undefined + csvData.forEach(data => { + // console.log('data:', data) + if (sponsorAddress == data.ethereum_address) { + existingData = data + } + }) + + if (!existingData) { + console.log('Add data for address:', sponsorAddress) + + const newData = { + ethereum_address: sponsorAddress, + sponsorship_count: 1, + distribution_count: 0, + impact_percentage: 0 // TODO + } + csvData.push(newData) + } else { + console.log('Update data for address:', sponsorAddress) + + existingData.sponsorship_count++ + } + }) + console.log('csvData:\n', csvData) + + // Export to CSV + // TODO +} From 09f2819f7511314547b7449e86b3e340d49801a5 Mon Sep 17 00:00:00 2001 From: nya-elimu Date: Tue, 6 Aug 2024 17:57:23 +0700 Subject: [PATCH 07/10] feat(distribution): calculate impact percentage #45 --- .../distribution/query-sponsorship-events.js | 39 +++++++++++++---- .../distribution/query-sponsorship-events.ts | 43 ++++++++++++++++--- 2 files changed, 67 insertions(+), 15 deletions(-) diff --git a/funding-splits/distribution/query-sponsorship-events.js b/funding-splits/distribution/query-sponsorship-events.js index f9b96e6..7c6e055 100644 --- a/funding-splits/distribution/query-sponsorship-events.js +++ b/funding-splits/distribution/query-sponsorship-events.js @@ -58,12 +58,12 @@ function query() { eventData.push([estimatedCost, timestamp, sponsorAddress]); } }); - exportToCsv(eventData); + prepareCsvData(eventData); }); } -function exportToCsv(eventData) { +function prepareCsvData(eventData) { return __awaiter(this, void 0, void 0, function* () { - console.log('exportToCsv'); + console.log('prepareCsvData'); console.log('eventData.length:', eventData.length); // Count events per sponsor address const csvData = []; @@ -94,8 +94,7 @@ function exportToCsv(eventData) { const newData = { ethereum_address: sponsorAddress, sponsorship_count: 1, - distribution_count: 0, - impact_percentage: 0 // TODO + distribution_count: 0 }; csvData.push(newData); } @@ -104,8 +103,32 @@ function exportToCsv(eventData) { existingData.sponsorship_count++; } }); - console.log('csvData:\n', csvData); - // Export to CSV - // TODO + console.log('csvData:', csvData); + calculateImpactPercentages(csvData); + exportToCsv(csvData); }); } +function calculateImpactPercentages(csvData) { + console.log('calculateImpactPercentages'); + let sponsorshipCountTotal = 0; + let distributionCountTotal = 0; + csvData.forEach(csvDataRow => { + sponsorshipCountTotal += csvDataRow.sponsorship_count; + distributionCountTotal += csvDataRow.distribution_count; + }); + console.log('sponsorshipCountTotal:', sponsorshipCountTotal); + console.log('distributionCountTotal:', distributionCountTotal); + // Calculate the impact percentage for each sponsor address + csvData.forEach(csvDataRow => { + const impactPercentage = 100 + * (csvDataRow.sponsorship_count + csvDataRow.distribution_count) + / (sponsorshipCountTotal + distributionCountTotal); + // console.log('impactPercentage:', impactPercentage) + csvDataRow.impact_percentage = impactPercentage; + }); + console.log('csvData:', csvData); +} +function exportToCsv(csvData) { + console.log('exportToCsv'); + // TODO +} diff --git a/funding-splits/distribution/query-sponsorship-events.ts b/funding-splits/distribution/query-sponsorship-events.ts index 0711f5e..8628063 100644 --- a/funding-splits/distribution/query-sponsorship-events.ts +++ b/funding-splits/distribution/query-sponsorship-events.ts @@ -64,11 +64,11 @@ async function query() { } }) - exportToCsv(eventData) + prepareCsvData(eventData) } -async function exportToCsv(eventData: any[]) { - console.log('exportToCsv') +async function prepareCsvData(eventData: any[]) { + console.log('prepareCsvData') console.log('eventData.length:', eventData.length) @@ -104,8 +104,7 @@ async function exportToCsv(eventData: any[]) { const newData = { ethereum_address: sponsorAddress, sponsorship_count: 1, - distribution_count: 0, - impact_percentage: 0 // TODO + distribution_count: 0 } csvData.push(newData) } else { @@ -114,8 +113,38 @@ async function exportToCsv(eventData: any[]) { existingData.sponsorship_count++ } }) - console.log('csvData:\n', csvData) + console.log('csvData:', csvData) + + calculateImpactPercentages(csvData) + + exportToCsv(csvData) +} + +function calculateImpactPercentages(csvData: any[]) { + console.log('calculateImpactPercentages') + + let sponsorshipCountTotal: number = 0 + let distributionCountTotal: number = 0 + csvData.forEach(csvDataRow => { + sponsorshipCountTotal += csvDataRow.sponsorship_count + distributionCountTotal += csvDataRow.distribution_count + }) + console.log('sponsorshipCountTotal:', sponsorshipCountTotal) + console.log('distributionCountTotal:', distributionCountTotal) + + // Calculate the impact percentage for each sponsor address + csvData.forEach(csvDataRow => { + const impactPercentage: number = 100 + * (csvDataRow.sponsorship_count + csvDataRow.distribution_count) + / (sponsorshipCountTotal + distributionCountTotal) + // console.log('impactPercentage:', impactPercentage) + csvDataRow.impact_percentage = impactPercentage + }) + console.log('csvData:', csvData) +} + +function exportToCsv(csvData: any[]) { + console.log('exportToCsv') - // Export to CSV // TODO } From 7770ea9b52f77baef6a1388961fc3476c7a451ba Mon Sep 17 00:00:00 2001 From: nya-elimu Date: Tue, 6 Aug 2024 18:12:28 +0700 Subject: [PATCH 08/10] feat(distribution): export to csv #45 --- .../distribution/FUNDING_SPLITS_HIN.csv | 6 ++++++ funding-splits/distribution/package-lock.json | 8 ++++++++ funding-splits/distribution/package.json | 3 +++ .../distribution/query-sponsorship-events.js | 18 +++++++++++++++++- .../distribution/query-sponsorship-events.ts | 19 ++++++++++++++++++- 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/funding-splits/distribution/FUNDING_SPLITS_HIN.csv b/funding-splits/distribution/FUNDING_SPLITS_HIN.csv index 08354d2..393545f 100644 --- a/funding-splits/distribution/FUNDING_SPLITS_HIN.csv +++ b/funding-splits/distribution/FUNDING_SPLITS_HIN.csv @@ -1 +1,7 @@ ethereum_address,sponsorship_count,distribution_count,impact_percentage +0xA7D1CB88740642DC95774511Cc73f015396Be869,4,0,44.44444444444444 +0x883753Beab357A2c29f3766C6ad158e72A78ce51,1,0,11.11111111111111 +0xFf7e232A44C74b306623f0d20dd6995775773842,1,0,11.11111111111111 +0xEbcF2690AF9e7D17e7dfB7118f65321Fc68d4b97,1,0,11.11111111111111 +0x29d6744eF3C98a00CAE8071D6DC292c53d6c5C75,1,0,11.11111111111111 +0x015B5dF1673499E32D11Cf786A43D1c42b3d725C,1,0,11.11111111111111 diff --git a/funding-splits/distribution/package-lock.json b/funding-splits/distribution/package-lock.json index 651a7db..4573045 100644 --- a/funding-splits/distribution/package-lock.json +++ b/funding-splits/distribution/package-lock.json @@ -8,6 +8,9 @@ "name": "distribution", "version": "0.0.1", "license": "MIT", + "dependencies": { + "csv-writer": "^1.6.0" + }, "devDependencies": { "ethers": "^6.13.2", "typescript": "^5.5.4" @@ -55,6 +58,11 @@ "integrity": "sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==", "dev": true }, + "node_modules/csv-writer": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/csv-writer/-/csv-writer-1.6.0.tgz", + "integrity": "sha512-NOx7YDFWEsM/fTRAJjRpPp8t+MKRVvniAg9wQlUKx20MFrPs73WLJhFf5iteqrxNYnsy924K3Iroh3yNHeYd2g==" + }, "node_modules/ethers": { "version": "6.13.2", "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.13.2.tgz", diff --git a/funding-splits/distribution/package.json b/funding-splits/distribution/package.json index fd02ab6..2f68159 100644 --- a/funding-splits/distribution/package.json +++ b/funding-splits/distribution/package.json @@ -11,5 +11,8 @@ "devDependencies": { "ethers": "^6.13.2", "typescript": "^5.5.4" + }, + "dependencies": { + "csv-writer": "^1.6.0" } } diff --git a/funding-splits/distribution/query-sponsorship-events.js b/funding-splits/distribution/query-sponsorship-events.js index 7c6e055..16cf666 100644 --- a/funding-splits/distribution/query-sponsorship-events.js +++ b/funding-splits/distribution/query-sponsorship-events.js @@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const ethers_1 = require("ethers"); const SponsorshipQueue_json_1 = __importDefault(require("./abis/SponsorshipQueue.json")); +const csv_writer_1 = require("csv-writer"); const rpcServerAddress = 'https://base-sepolia.blockpi.network/v1/rpc/public'; console.log('rpcServerAddress:', rpcServerAddress); const provider = new ethers_1.ethers.JsonRpcProvider(rpcServerAddress); @@ -130,5 +131,20 @@ function calculateImpactPercentages(csvData) { } function exportToCsv(csvData) { console.log('exportToCsv'); - // TODO + const outputPath = 'FUNDING_SPLITS_HIN.csv'; + console.log('outputPath:', outputPath); + const csvWriter = (0, csv_writer_1.createObjectCsvWriter)({ + path: outputPath, + header: [ + { id: 'ethereum_address', title: 'ethereum_address' }, + { id: 'sponsorship_count', title: 'sponsorship_count' }, + { id: 'distribution_count', title: 'distribution_count' }, + { id: 'impact_percentage', title: 'impact_percentage' } + ] + }); + csvWriter + .writeRecords(csvData) + .then(() => { + console.log('The CSV file was written successfully:', outputPath); + }); } diff --git a/funding-splits/distribution/query-sponsorship-events.ts b/funding-splits/distribution/query-sponsorship-events.ts index 8628063..7dac274 100644 --- a/funding-splits/distribution/query-sponsorship-events.ts +++ b/funding-splits/distribution/query-sponsorship-events.ts @@ -1,5 +1,6 @@ import { Contract, ethers, EventLog, JsonRpcProvider, Log, Result } from 'ethers' import SponsorshipQueue from './abis/SponsorshipQueue.json' +import { createObjectCsvWriter as createCsvWriter } from 'csv-writer' const rpcServerAddress: string = 'https://base-sepolia.blockpi.network/v1/rpc/public' console.log('rpcServerAddress:', rpcServerAddress) @@ -146,5 +147,21 @@ function calculateImpactPercentages(csvData: any[]) { function exportToCsv(csvData: any[]) { console.log('exportToCsv') - // TODO + const outputPath: string = 'FUNDING_SPLITS_HIN.csv' + console.log('outputPath:', outputPath) + const csvWriter = createCsvWriter({ + path: outputPath, + header: [ + {id: 'ethereum_address', title: 'ethereum_address'}, + {id: 'sponsorship_count', title: 'sponsorship_count'}, + {id: 'distribution_count', title: 'distribution_count'}, + {id: 'impact_percentage', title: 'impact_percentage'} + ] + }) + + csvWriter + .writeRecords(csvData) + .then(() => { + console.log('The CSV file was written successfully:', outputPath) + }) } From f9d61464ea42d1f8c06c9423e58419cdd6d81284 Mon Sep 17 00:00:00 2001 From: nya-elimu Date: Tue, 6 Aug 2024 18:13:04 +0700 Subject: [PATCH 09/10] Delete query-sponsorship-events.js --- .../distribution/query-sponsorship-events.js | 150 ------------------ 1 file changed, 150 deletions(-) delete mode 100644 funding-splits/distribution/query-sponsorship-events.js diff --git a/funding-splits/distribution/query-sponsorship-events.js b/funding-splits/distribution/query-sponsorship-events.js deleted file mode 100644 index 16cf666..0000000 --- a/funding-splits/distribution/query-sponsorship-events.js +++ /dev/null @@ -1,150 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const ethers_1 = require("ethers"); -const SponsorshipQueue_json_1 = __importDefault(require("./abis/SponsorshipQueue.json")); -const csv_writer_1 = require("csv-writer"); -const rpcServerAddress = 'https://base-sepolia.blockpi.network/v1/rpc/public'; -console.log('rpcServerAddress:', rpcServerAddress); -const provider = new ethers_1.ethers.JsonRpcProvider(rpcServerAddress); -// console.log('provider:', provider) -const sponsorshipQueueContract = new ethers_1.ethers.Contract('0x9Af2E73663968fdfb9791b7D6Bd40cd259f0388a', SponsorshipQueue_json_1.default.abi, provider); -// console.log('sponsorshipQueueContract:', sponsorshipQueueContract) -query(); -function query() { - return __awaiter(this, void 0, void 0, function* () { - console.log('query'); - const events = yield sponsorshipQueueContract.queryFilter('*'); - console.log('events.length:', events.length); - const eventData = []; - events.forEach((eventLog) => { - console.log(''); - // console.log('eventLog:', eventLog) - const blockNumber = eventLog.blockNumber; - console.log('blockNumber:', eventLog.blockNumber); - const eventName = eventLog.fragment.name; - console.log('eventName:', eventName); - const argResult = eventLog.args; - // console.log('argResult:', argResult) - // - // Sample: - // - // Result(1) [ - // Result(3) [ - // 2000000000000000n, - // 1721578316n, - // '0x015B5dF1673499E32D11Cf786A43D1c42b3d725C' - // ] - // ] - if (eventName == 'SponsorshipAdded') { - const argResultArray = argResult[0]; - // console.log('argResultArray:', argResultArray) - const estimatedCost = argResultArray[0]; - console.log('estimatedCost:', estimatedCost); - const timestamp = argResultArray[1]; - console.log('timestamp:', timestamp); - const sponsorAddress = argResultArray[2]; - console.log('sponsorAddress:', sponsorAddress); - eventData.push([estimatedCost, timestamp, sponsorAddress]); - } - }); - prepareCsvData(eventData); - }); -} -function prepareCsvData(eventData) { - return __awaiter(this, void 0, void 0, function* () { - console.log('prepareCsvData'); - console.log('eventData.length:', eventData.length); - // Count events per sponsor address - const csvData = []; - // Sample: - // - // [ - // { - // ethereum_address: '0x015B5dF1673499E32D11Cf786A43D1c42b3d725C' - // sponsorship_count: 1 - // distribution_count: 0 - // impact_percentage: 100 - // } - // ] - eventData.forEach(sponsorshipEvent => { - const estimatedCost = sponsorshipEvent[0]; - const timestamp = sponsorshipEvent[1]; - const sponsorAddress = sponsorshipEvent[2]; - // Check if data already exists for the sponsor address - let existingData = undefined; - csvData.forEach(data => { - // console.log('data:', data) - if (sponsorAddress == data.ethereum_address) { - existingData = data; - } - }); - if (!existingData) { - console.log('Add data for address:', sponsorAddress); - const newData = { - ethereum_address: sponsorAddress, - sponsorship_count: 1, - distribution_count: 0 - }; - csvData.push(newData); - } - else { - console.log('Update data for address:', sponsorAddress); - existingData.sponsorship_count++; - } - }); - console.log('csvData:', csvData); - calculateImpactPercentages(csvData); - exportToCsv(csvData); - }); -} -function calculateImpactPercentages(csvData) { - console.log('calculateImpactPercentages'); - let sponsorshipCountTotal = 0; - let distributionCountTotal = 0; - csvData.forEach(csvDataRow => { - sponsorshipCountTotal += csvDataRow.sponsorship_count; - distributionCountTotal += csvDataRow.distribution_count; - }); - console.log('sponsorshipCountTotal:', sponsorshipCountTotal); - console.log('distributionCountTotal:', distributionCountTotal); - // Calculate the impact percentage for each sponsor address - csvData.forEach(csvDataRow => { - const impactPercentage = 100 - * (csvDataRow.sponsorship_count + csvDataRow.distribution_count) - / (sponsorshipCountTotal + distributionCountTotal); - // console.log('impactPercentage:', impactPercentage) - csvDataRow.impact_percentage = impactPercentage; - }); - console.log('csvData:', csvData); -} -function exportToCsv(csvData) { - console.log('exportToCsv'); - const outputPath = 'FUNDING_SPLITS_HIN.csv'; - console.log('outputPath:', outputPath); - const csvWriter = (0, csv_writer_1.createObjectCsvWriter)({ - path: outputPath, - header: [ - { id: 'ethereum_address', title: 'ethereum_address' }, - { id: 'sponsorship_count', title: 'sponsorship_count' }, - { id: 'distribution_count', title: 'distribution_count' }, - { id: 'impact_percentage', title: 'impact_percentage' } - ] - }); - csvWriter - .writeRecords(csvData) - .then(() => { - console.log('The CSV file was written successfully:', outputPath); - }); -} From 5ba16c3081d1cb19a5dd450c7926b4cf519cbb93 Mon Sep 17 00:00:00 2001 From: nya-elimu Date: Tue, 6 Aug 2024 18:13:35 +0700 Subject: [PATCH 10/10] Update .gitignore --- funding-splits/distribution/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/funding-splits/distribution/.gitignore b/funding-splits/distribution/.gitignore index 3c3629e..a3413de 100644 --- a/funding-splits/distribution/.gitignore +++ b/funding-splits/distribution/.gitignore @@ -1 +1,2 @@ node_modules +query-sponsorship-events.js