From 408a76cb8c5a0fd14a661e23225d095bc18eec31 Mon Sep 17 00:00:00 2001 From: EjembiEmmanuel Date: Fri, 30 Aug 2024 12:47:56 +0100 Subject: [PATCH] fix: fix unruggableMemecoin deploy indexer --- .vscode/settings.json | 3 + apps/indexer/docker-compose.yml | 51 ++++++------- apps/indexer/init.sql | 14 ++-- .../src/{constants.js => constants.ts} | 0 apps/indexer/src/deps.js | 6 -- apps/indexer/src/deps.ts | 11 +++ .../src/unruggableMemecoin-deploy.indexer.js | 58 --------------- .../src/unruggableMemecoin-deploy.indexer.ts | 74 +++++++++++++++++++ 8 files changed, 120 insertions(+), 97 deletions(-) create mode 100644 .vscode/settings.json rename apps/indexer/src/{constants.js => constants.ts} (100%) delete mode 100644 apps/indexer/src/deps.js create mode 100644 apps/indexer/src/deps.ts delete mode 100644 apps/indexer/src/unruggableMemecoin-deploy.indexer.js create mode 100644 apps/indexer/src/unruggableMemecoin-deploy.indexer.ts diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..cbac5697 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "deno.enable": true +} diff --git a/apps/indexer/docker-compose.yml b/apps/indexer/docker-compose.yml index 6542bf90..941f574e 100644 --- a/apps/indexer/docker-compose.yml +++ b/apps/indexer/docker-compose.yml @@ -17,8 +17,9 @@ services: unruggableMemecoin-deploy-indexer: environment: - AUTH_TOKEN=${AUTH_TOKEN} + - DATABASE_CONN_STRING=${DATABASE_CONN_STRING} image: quay.io/apibara/sink-postgres:latest - command: 'run ./indexer/unruggableMemecoin-deploy.indexer.ts --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}' + command: 'run ./indexer/unruggableMemecoin-deploy.indexer.ts --allow-env-from-env AUTH_TOKEN,DATABASE_CONN_STRING -A ${AUTH_TOKEN}' volumes: - ./src:/indexer depends_on: @@ -27,31 +28,31 @@ services: - backend restart: on-failure - unruggableMemecoin-launch-indexer: - environment: - - AUTH_TOKEN=${AUTH_TOKEN} - image: quay.io/apibara/sink-postgres:latest - command: 'run ./indexer/unruggableMemecoin-launch.indexer.ts --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}' - volumes: - - ./src:/indexer - depends_on: - - postgres - networks: - - backend - restart: on-failure + # unruggableMemecoin-launch-indexer: + # environment: + # - AUTH_TOKEN=${AUTH_TOKEN} + # image: quay.io/apibara/sink-postgres:latest + # command: 'run ./indexer/unruggableMemecoin-launch.indexer.js --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}' + # volumes: + # - ./src:/indexer + # depends_on: + # - postgres + # networks: + # - backend + # restart: on-failure - unruggableMemecoin-transfers-indexer: - environment: - - AUTH_TOKEN=${AUTH_TOKEN} - image: quay.io/apibara/sink-postgres:latest - command: 'run ./indexer/unruggableMemecoin-transfers.indexer.ts --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}' - volumes: - - ./src:/indexer - depends_on: - - postgres - networks: - - backend - restart: on-failure + # unruggableMemecoin-transfers-indexer: + # environment: + # - AUTH_TOKEN=${AUTH_TOKEN} + # image: quay.io/apibara/sink-postgres:latest + # command: 'run ./indexer/unruggableMemecoin-transfers.indexer.js --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}' + # volumes: + # - ./src:/indexer + # depends_on: + # - postgres + # networks: + # - backend + # restart: on-failure networks: backend: diff --git a/apps/indexer/init.sql b/apps/indexer/init.sql index 1344bb05..06937b4a 100644 --- a/apps/indexer/init.sql +++ b/apps/indexer/init.sql @@ -12,10 +12,8 @@ create table token_launch( current_supply text, liquidity_raised text, price text, - _cursor bigint - timestamp TIMESTAMP, - - + _cursor bigint, + time_stamp timestamp ); create table token_deploy( @@ -32,8 +30,8 @@ create table token_deploy( initial_supply text, total_supply text, created_at timestamp default current_timestamp, - _cursor bigint - timestamp TIMESTAMP, + _cursor bigint, + time_stamp TIMESTAMP ); @@ -58,9 +56,9 @@ CREATE TABLE token_transactions ( liquidity_raised TEXT, price TEXT, amount TEXT, - timestamp TIMESTAMP, + time_stamp timestamp, _cursor bigint, - transaction_type TEXT NOT NULL CHECK (transaction_type IN ('buy', 'sell')),, + transaction_type TEXT NOT NULL CHECK (transaction_type IN ('buy', 'sell')) ); diff --git a/apps/indexer/src/constants.js b/apps/indexer/src/constants.ts similarity index 100% rename from apps/indexer/src/constants.js rename to apps/indexer/src/constants.ts diff --git a/apps/indexer/src/deps.js b/apps/indexer/src/deps.js deleted file mode 100644 index b7b93c9e..00000000 --- a/apps/indexer/src/deps.js +++ /dev/null @@ -1,6 +0,0 @@ -export { ec, hash, uint256, shortString } from 'https://esm.sh/starknet@5.14' -export { formatUnits } from 'https://esm.sh/viem@1.4' - -export { Block, FieldElement, Filter } from 'https://esm.sh/@apibara/indexer@0.3/starknet' -// export { Config, NetworkOptions } from "https://esm.sh/@apibara/indexer"; -// export { Console } from "https://esm.sh/@apibara/indexer/sink/console"; \ No newline at end of file diff --git a/apps/indexer/src/deps.ts b/apps/indexer/src/deps.ts new file mode 100644 index 00000000..7c1b9bb1 --- /dev/null +++ b/apps/indexer/src/deps.ts @@ -0,0 +1,11 @@ +export { ec, hash, uint256, shortString } from "https://esm.sh/starknet@5.14"; +export { formatUnits } from "https://esm.sh/viem@1.4"; + +// export { Block, FieldElement, Filter } from 'https://esm.sh/@apibara/indexer@0.3/starknet' +export type { + Block, + FieldElement, + Filter +} from "https://esm.sh/@apibara/indexer@0.3.1/starknet"; +// export { Config, NetworkOptions } from "https://esm.sh/@apibara/indexer"; +// export { Console } from "https://esm.sh/@apibara/indexer/sink/console"; diff --git a/apps/indexer/src/unruggableMemecoin-deploy.indexer.js b/apps/indexer/src/unruggableMemecoin-deploy.indexer.js deleted file mode 100644 index afd86604..00000000 --- a/apps/indexer/src/unruggableMemecoin-deploy.indexer.js +++ /dev/null @@ -1,58 +0,0 @@ -import { hash, shortString, uint256 } from './deps.ts' -import { FACTORY_ADDRESS, STARTING_BLOCK } from './constants.ts' - -const filter = { - header: { - weak: true, - }, - events: [ - { - fromAddress: FACTORY_ADDRESS, - keys: [hash.getSelectorFromName('MemecoinCreated')], - includeReceipt: false, - }, - ], -} - -export const config = { - streamUrl: 'https://mainnet.starknet.a5a.ch', - startingBlock: STARTING_BLOCK, - network: 'starknet', - finality: 'DATA_STATUS_ACCEPTED', - filter, - sinkType: 'postgres', - sinkOptions: { - connectionString: '', - tableName: 'unrugmeme_deploy', - }, -} - -export default function DecodeUnruggableMemecoinDeploy({ header, events }) { - const { blockNumber, blockHash, timestamp } = header - - return (events ?? []).map(({ event, transaction }) => { - if (!event.data) return - - const transactionHash = transaction.meta.hash - - const [owner, name, symbol, initial_supply_low, initial_supply_high, memecoin_address] = event.data - - const name_decoded = shortString.decodeShortString(name.replace(/0x0+/, '0x')) - const symbol_decoded = shortString.decodeShortString(symbol.replace(/0x0+/, '0x')) - const initial_supply = uint256.uint256ToBN({ low: initial_supply_low, high: initial_supply_high }).toString() - - return { - network: 'starknet-mainnet', - block_hash: blockHash, - block_number: Number(blockNumber), - block_timestamp: timestamp, - transaction_hash: transactionHash, - memecoin_address: memecoin_address, - owner_address: owner, - name: name_decoded, - symbol: symbol_decoded, - initial_supply: initial_supply, - created_at: new Date().toISOString(), - } - }) -} diff --git a/apps/indexer/src/unruggableMemecoin-deploy.indexer.ts b/apps/indexer/src/unruggableMemecoin-deploy.indexer.ts new file mode 100644 index 00000000..71405a49 --- /dev/null +++ b/apps/indexer/src/unruggableMemecoin-deploy.indexer.ts @@ -0,0 +1,74 @@ +import { Block, hash, shortString, uint256 } from "./deps.ts"; +import { FACTORY_ADDRESS, STARTING_BLOCK } from "./constants.ts"; + +const filter = { + header: { + weak: true + }, + events: [ + { + fromAddress: FACTORY_ADDRESS, + keys: [hash.getSelectorFromName("MemecoinCreated")], + includeReceipt: false + } + ] +}; + +export const config = { + streamUrl: "https://mainnet.starknet.a5a.ch", + startingBlock: STARTING_BLOCK, + network: "starknet", + finality: "DATA_STATUS_ACCEPTED", + filter, + sinkType: "postgres", + sinkOptions: { + connectionString: Deno.env.get("DATABASE_CONN_STRING"), + tableName: "unrugmeme_deploy" + } +}; + +export default function DecodeUnruggableMemecoinDeploy({ + header, + events +}: Block) { + const { blockNumber, blockHash, timestamp } = header!; + + return (events ?? []).map(({ event, transaction }) => { + if (!event.data) return; + + const transactionHash = transaction.meta.hash; + + const [ + owner, + name, + symbol, + initial_supply_low, + initial_supply_high, + memecoin_address + ] = event.data; + + const name_decoded = shortString.decodeShortString( + name.replace(/0x0+/, "0x") + ); + const symbol_decoded = shortString.decodeShortString( + symbol.replace(/0x0+/, "0x") + ); + const initial_supply = uint256 + .uint256ToBN({ low: initial_supply_low, high: initial_supply_high }) + .toString(); + + return { + network: "starknet-mainnet", + block_hash: blockHash, + block_number: Number(blockNumber), + block_timestamp: timestamp, + transaction_hash: transactionHash, + memecoin_address: memecoin_address, + owner_address: owner, + name: name_decoded, + symbol: symbol_decoded, + initial_supply: initial_supply, + created_at: new Date().toISOString() + }; + }); +}