diff --git a/package.json b/package.json index 2306ab1f..9d77d3fb 100644 --- a/package.json +++ b/package.json @@ -6,14 +6,14 @@ ], "type": "module", "dependencies": { - "@sentio/sdk": "^2.21.3-rc.2", + "@sentio/sdk": "^2.22.0-rc.1", "node-fetch": "^3.3.1" }, "resolutions": { "ethers": "npm:@sentio/ethers@6.6.0" }, "devDependencies": { - "@sentio/cli": "^2.9.0", + "@sentio/cli": "^2.9.3", "ts-node": "^10.9.1", "typescript": "^5.0.4" }, diff --git a/projects/forked-pools/.gitignore b/projects/forked-pools/.gitignore new file mode 100644 index 00000000..87081652 --- /dev/null +++ b/projects/forked-pools/.gitignore @@ -0,0 +1,107 @@ +.idea +src/types + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and *not* Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port diff --git a/projects/forked-pools/abis/eth/uniswap-v2-factory.json b/projects/forked-pools/abis/eth/uniswap-v2-factory.json new file mode 100644 index 00000000..b4053904 --- /dev/null +++ b/projects/forked-pools/abis/eth/uniswap-v2-factory.json @@ -0,0 +1,193 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "_feeToSetter", + "type": "address" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "pair", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "PairCreated", + "type": "event" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "allPairs", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "allPairsLength", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "tokenA", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenB", + "type": "address" + } + ], + "name": "createPair", + "outputs": [ + { + "internalType": "address", + "name": "pair", + "type": "address" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "feeTo", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "feeToSetter", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "getPair", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "_feeTo", + "type": "address" + } + ], + "name": "setFeeTo", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "_feeToSetter", + "type": "address" + } + ], + "name": "setFeeToSetter", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/projects/forked-pools/abis/eth/uniswap-v3-factory.json b/projects/forked-pools/abis/eth/uniswap-v3-factory.json new file mode 100644 index 00000000..63f8e7a5 --- /dev/null +++ b/projects/forked-pools/abis/eth/uniswap-v3-factory.json @@ -0,0 +1,236 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "indexed": true, + "internalType": "int24", + "name": "tickSpacing", + "type": "int24" + } + ], + "name": "FeeAmountEnabled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "oldOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnerChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "indexed": false, + "internalType": "int24", + "name": "tickSpacing", + "type": "int24" + }, + { + "indexed": false, + "internalType": "address", + "name": "pool", + "type": "address" + } + ], + "name": "PoolCreated", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenA", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenB", + "type": "address" + }, + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + } + ], + "name": "createPool", + "outputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "internalType": "int24", + "name": "tickSpacing", + "type": "int24" + } + ], + "name": "enableFeeAmount", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint24", + "name": "", + "type": "uint24" + } + ], + "name": "feeAmountTickSpacing", + "outputs": [ + { + "internalType": "int24", + "name": "", + "type": "int24" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "uint24", + "name": "", + "type": "uint24" + } + ], + "name": "getPool", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "parameters", + "outputs": [ + { + "internalType": "address", + "name": "factory", + "type": "address" + }, + { + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + }, + { + "internalType": "int24", + "name": "tickSpacing", + "type": "int24" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_owner", + "type": "address" + } + ], + "name": "setOwner", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/projects/forked-pools/jest.config.ts b/projects/forked-pools/jest.config.ts new file mode 100644 index 00000000..a1663671 --- /dev/null +++ b/projects/forked-pools/jest.config.ts @@ -0,0 +1,8 @@ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ +export default { + preset: 'ts-jest/presets/default-esm', + modulePathIgnorePatterns: ['/dist/'], + moduleNameMapper: { + '^(\\.{1,2}/.*)\\.js$': '$1', + }, +} diff --git a/projects/forked-pools/package.json b/projects/forked-pools/package.json new file mode 100644 index 00000000..ebd19b8b --- /dev/null +++ b/projects/forked-pools/package.json @@ -0,0 +1,13 @@ +{ + "name": "forked-pools", + "private": true, + "version": "1.0.0", + "type": "module", + "scripts": { + "test": "sentio test", + "gen": "sentio gen", + "build": "sentio build", + "upload": "sentio upload", + "postinstall": "sentio gen" + } +} \ No newline at end of file diff --git a/projects/forked-pools/sentio.yaml b/projects/forked-pools/sentio.yaml new file mode 100644 index 00000000..c9b81654 --- /dev/null +++ b/projects/forked-pools/sentio.yaml @@ -0,0 +1 @@ +project: forked-pools diff --git a/projects/forked-pools/src/processor.test.ts b/projects/forked-pools/src/processor.test.ts new file mode 100644 index 00000000..a1a779a3 --- /dev/null +++ b/projects/forked-pools/src/processor.test.ts @@ -0,0 +1,28 @@ +import { TestProcessorServer, firstCounterValue } from '@sentio/sdk/testing' +import { mockTransferLog } from '@sentio/sdk/eth/builtin/erc20' + +describe('Test Processor', () => { + const service = new TestProcessorServer(() => import('./processor.js')) + + beforeAll(async () => { + await service.start() + }) + + test('has valid config', async () => { + const config = await service.getConfig({}) + expect(config.contractConfigs.length > 0).toBeTruthy() + }) + + test('check transfer event handling', async () => { + const resp = await service.eth.testLog( + mockTransferLog('0x1e4ede388cbc9f4b5c79681b7f94d36a11abebc9', { + from: '0x0000000000000000000000000000000000000000', + to: '0xb329e39ebefd16f40d38f07643652ce17ca5bac1', + value: 10n ** 18n * 10n, + }) + ) + + const tokenCounter = firstCounterValue(resp.result, 'token') + expect(tokenCounter).toEqual(10n) + }) +}) diff --git a/projects/forked-pools/src/processor.ts b/projects/forked-pools/src/processor.ts new file mode 100644 index 00000000..314744c9 --- /dev/null +++ b/projects/forked-pools/src/processor.ts @@ -0,0 +1,29 @@ +import { UniswapV2FactoryProcessor , UniswapV3FactoryProcessor} from "./types/eth/index.js"; + +UniswapV2FactoryProcessor.bind({address: '*', startBlock: 10000835}) + .onEventPairCreated((evt, ctx) => { + + ctx.meter.Counter("pool").add(1, { + poolType: "UniswapV2", + }) + + ctx.eventLogger.emit("PoolCreated", { + poolType: "UniswapV2", + address: evt.args.pair + }) + }) + +UniswapV3FactoryProcessor.bind({address: '*', startBlock: 12369621}) + .onEventPoolCreated((evt, ctx) => { + ctx.meter.Counter("pool").add(1, { + poolType: "UniswapV2", + }) + + ctx.eventLogger.emit("PoolCreated", { + poolType: "UniswapV2", + address: evt.args.pool + }) + }) + +// + diff --git a/projects/forked-pools/tsconfig.json b/projects/forked-pools/tsconfig.json new file mode 100644 index 00000000..03c7d8c7 --- /dev/null +++ b/projects/forked-pools/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "importHelpers": true, + "alwaysStrict": true, + "sourceMap": true, + "target": "esnext", + "esModuleInterop": true, + "noImplicitReturns": true, + "noImplicitAny": true, + "module": "esnext", + "moduleResolution": "nodenext", + "strictNullChecks": true, + "stripInternal": true, + "noFallthroughCasesInSwitch": true, + "noEmitOnError": false, + "rootDir": "./src", + "outDir": "./dist", + "skipLibCheck": true + }, + "exclude": ["dist", "jest.config.ts"] +} diff --git a/yarn.lock b/yarn.lock index 2023ac7f..2889cc73 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1277,10 +1277,10 @@ truffle-privatekey-provider "^1.5.0" web3 "^1.3.0" -"@sentio/protos@2.21.3-rc.2": - version "2.21.3-rc.2" - resolved "https://registry.yarnpkg.com/@sentio/protos/-/protos-2.21.3-rc.2.tgz#c8b1f2eaa836d13a35294d79ff45fda77a592722" - integrity sha512-qajudWq5HRnH9l10elm0E8RaGZhJsm4CDMKU6/ivqb2wvxIU/QufeWMzYMnAihuRZcUYTiivLGQxXJKkzgkDKg== +"@sentio/protos@2.22.0-rc.1": + version "2.22.0-rc.1" + resolved "https://registry.yarnpkg.com/@sentio/protos/-/protos-2.22.0-rc.1.tgz#b1ba813d74b82eb38ff73a673056cc43ca715804" + integrity sha512-2TA4/sLOXJSSyj/TGxZQsvXKDhM2lkx6w/2ci5O8we1gijWw5t/WGoiDCPbyu6cvRakGzYNoJnPmkmnmBrfMtw== dependencies: google-protobuf "^3.21.2" long "^5.2.3" @@ -1288,13 +1288,13 @@ nice-grpc-common "^2.0.2" protobufjs "^7.2.3" -"@sentio/runtime@^2.21.3-rc.2": - version "2.21.3-rc.2" - resolved "https://registry.yarnpkg.com/@sentio/runtime/-/runtime-2.21.3-rc.2.tgz#6b45cf62292abb19ea54a605d8f495c753c180d5" - integrity sha512-viCfOXbHyMuzuCMaudV3gCapRmgNA4aq12oTdXUFliy9kNsooP8bn88jApDBOgmekCLRvTwFH5PcW0TMgsnU7g== +"@sentio/runtime@^2.22.0-rc.1": + version "2.22.0-rc.1" + resolved "https://registry.yarnpkg.com/@sentio/runtime/-/runtime-2.22.0-rc.1.tgz#8bd2c682fe0f01e7a2097faeaf514cee30a07e3a" + integrity sha512-Fy1ud9yFPDeRUiPRkQPM5/eL9Eoge0F18ugsEwzan/iUMmazZflODGXDX/UrKQdb9pvU5w4nf/otzNhwsTkhKQ== dependencies: "@grpc/grpc-js" "^1.8.14" - "@sentio/protos" "2.21.3-rc.2" + "@sentio/protos" "2.22.0-rc.1" command-line-args "^5.2.1" command-line-usage "^7.0.1" fs-extra "^11.0.0" @@ -1310,10 +1310,10 @@ utility-types "^3.10.0" winston "^3.8.2" -"@sentio/sdk@^2.21.3-rc.2": - version "2.21.3-rc.2" - resolved "https://registry.yarnpkg.com/@sentio/sdk/-/sdk-2.21.3-rc.2.tgz#76d8fa85500e8f2b2179e1c22d9f62ebb379dd6b" - integrity sha512-y0Ieu2xTUI4LxjTvBZ4czcy8NAyLsxxY34bOBZkmMPSVY88UijuL/puy4G4N7Pu+FH491Vb1OGqqEKfpe0L2qQ== +"@sentio/sdk@^2.22.0-rc.1": + version "2.22.0-rc.1" + resolved "https://registry.yarnpkg.com/@sentio/sdk/-/sdk-2.22.0-rc.1.tgz#f125346360a41cf630143b926047c648fa9d7863" + integrity sha512-PA7JcVuok3G4ZYdK9+SoMwp9SEYuVL99pnbmn0/QNxqjHH0C/bIFI31Rgd1Y/tYO8oTr/51aalqnyxKEawieFg== dependencies: "@coral-xyz/borsh" "^0.28.0" "@mysten/sui.js" "^0.36.0" @@ -1321,8 +1321,8 @@ "@sentio/bigdecimal" "^9.1.1-patch.3" "@sentio/chain" "^1.0.0" "@sentio/ethers-v6" "^1.0.28" - "@sentio/protos" "2.21.3-rc.2" - "@sentio/runtime" "^2.21.3-rc.2" + "@sentio/protos" "2.22.0-rc.1" + "@sentio/runtime" "^2.22.0-rc.1" "@solana/web3.js" "^1.74.0" "@types/prettier" "^2.7.2" aptos-sdk "npm:aptos@^1.10.0"