diff --git a/apps/indexer/Dockerfile b/apps/indexer/Dockerfile index e5fa3914..9f5c6e32 100644 --- a/apps/indexer/Dockerfile +++ b/apps/indexer/Dockerfile @@ -11,4 +11,8 @@ FROM quay.io/apibara/sink-postgres:0.7.0-x86_64 WORKDIR /app COPY ./src/* /app +ARG DATABASE_CONN_STRING + +ENV DATABASE_CONN_STRING=${DATABASE_CONN_STRING} + ENTRYPOINT ["/nix/store/rh1g8pb7wfnyr527jfmkkc5lm3sa1f0l-apibara-sink-postgres-0.7.0/bin/apibara-sink-postgres"] diff --git a/apps/indexer/README.md b/apps/indexer/README.md index 0f159b8a..6c3a5609 100644 --- a/apps/indexer/README.md +++ b/apps/indexer/README.md @@ -27,4 +27,4 @@ apibara run ./src/pump-buy-coin.js -A dna_XXX ``` ### Run it - docker run -it --env-file ./.env afk-indexer run /app/pump-deploy-coin.js --tls-accept-invalid-certificates=true --connection-string POSTGRES:INDEXER_DATABASE_URL \ No newline at end of file + docker run -it --env-file ./.env afk-indexer run /app/buy-token --tls-accept-invalid-certificates=true --allow-env-from-env DATABASE_CONN_STRING \ No newline at end of file diff --git a/apps/indexer/src/buy-token.ts b/apps/indexer/src/buy-token.ts index 258bfd98..6ba289e3 100644 --- a/apps/indexer/src/buy-token.ts +++ b/apps/indexer/src/buy-token.ts @@ -22,29 +22,34 @@ export const config = { filter, sinkType: "postgres", sinkOptions: { - connectionString: "", // Specify your PostgreSQL connection string here + connectionString: Deno.env.get("DATABASE_CONN_STRING"), tableName: "token_transactions" } }; export default function DecodeBuyToken({ header, events }: Block) { - const { blockNumber, blockHash, timestamp } = header!; + const { blockNumber, blockHash, timestamp: block_timestamp } = header!; return (events ?? []).map(({ event, transaction }) => { if (!event.data) return; const transactionHash = transaction.meta.hash; + const transfer_id = `${transactionHash}_${event.index}`; + + const [caller, token_address] = event.keys!; + const [ - caller, - token_address, amount_low, amount_high, price_low, price_high, protocol_fee_low, protocol_fee_high, - initial_supply_low, - initial_supply_high + last_price_low, + last_price_high, + timestamp, + quote_amount_low, + quote_amount_high ] = event.data; const amount = uint256 @@ -56,24 +61,29 @@ export default function DecodeBuyToken({ header, events }: Block) { const protocol_fee = uint256 .uint256ToBN({ low: protocol_fee_low, high: protocol_fee_high }) .toString(); - const initial_supply = uint256 - .uint256ToBN({ low: initial_supply_low, high: initial_supply_high }) + const last_price = uint256 + .uint256ToBN({ low: last_price_low, high: last_price_high }) + .toString(); + const quote_amount = uint256 + .uint256ToBN({ low: quote_amount_low, high: quote_amount_high }) .toString(); return { - transaction_type: "buy", + transfer_id, network: "starknet-sepolia", block_hash: blockHash, block_number: Number(blockNumber), - block_timestamp: timestamp, + block_timestamp: block_timestamp, transaction_hash: transactionHash, memecoin_address: token_address, owner_address: caller, - initial_supply, + last_price, + quote_amount, price, + amount, protocol_fee, - timestamp: new Date(Number(timestamp) * 1000).toISOString(), // UNIX timestamp to ISO string - created_at: new Date().toISOString() + timestamp: timestamp, + transaction_type: "buy" }; }); }