Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix apps/indexer apibara and endpoints #98

Merged
merged 13 commits into from
Aug 30, 2024
Merged
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"deno.enable": true
}
2 changes: 2 additions & 0 deletions apps/indexer/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
AUTH_TOKEN=dna_xxx
POSTGRES_CONNECTION_STRING=postgresql://admin:postgres@localhost:5432/indexer
4 changes: 4 additions & 0 deletions apps/indexer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ FROM quay.io/apibara/sink-postgres:0.7.0-x86_64
WORKDIR /app
COPY ./src/* /app

ARG POSTGRES_CONNECTION_STRING

ENV POSTGRES_CONNECTION_STRING=${POSTGRES_CONNECTION_STRING}

ENTRYPOINT ["/nix/store/rh1g8pb7wfnyr527jfmkkc5lm3sa1f0l-apibara-sink-postgres-0.7.0/bin/apibara-sink-postgres"]
9 changes: 4 additions & 5 deletions apps/indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
## Install Postgres and Init the tables

```
docker run --name afk-indexer -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 -v /afk-indexer:/docker-entrypoint-initdb.d postgres:16
docker run --name afk-indexer -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=admin -e POSTGRES_DB=indexer -d -p 5432:5432 -v ./:/docker-entrypoint-initdb.d postgres:latest
```

# Test

unrugmeme_deploy
buy-token deploy

```
apibara run ./src/pump-buy-coin.js -A dna_XXX

apibara run ./src/buy-token.ts --allow-env .env -A dna_xxx

```

Expand All @@ -27,4 +26,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
docker run -it --env-file ./.env afk-indexer run /app/buy-token.ts --tls-accept-invalid-certificates=true --allow-env-from-env POSTGRES_CONNECTION_STRING
23 changes: 15 additions & 8 deletions apps/indexer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
environment:
POSTGRES_DB: indexer
POSTGRES_USER: admin
POSTGRES_PASSWORD: password
POSTGRES_PASSWORD: postgres
ports:
- '5432:5432'
volumes:
Expand All @@ -17,8 +17,9 @@ services:
unruggableMemecoin-deploy-indexer:
environment:
- AUTH_TOKEN=${AUTH_TOKEN}
- POSTGRES_CONNECTION_STRING=postgresql://admin:postgres@postgres:5432/indexer
image: quay.io/apibara/sink-postgres:latest
command: 'run ./indexer/unruggableMemecoin-deploy.indexer.js --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}'
command: 'run ./indexer/unruggableMemecoin-deploy.indexer.ts --allow-env-from-env AUTH_TOKEN,POSTGRES_CONNECTION_STRING -A ${AUTH_TOKEN}'
volumes:
- ./src:/indexer
depends_on:
Expand All @@ -30,8 +31,9 @@ services:
unruggableMemecoin-launch-indexer:
environment:
- AUTH_TOKEN=${AUTH_TOKEN}
- POSTGRES_CONNECTION_STRING=postgresql://admin:postgres@postgres:5432/indexer
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}'
command: 'run ./indexer/unruggableMemecoin-launch.indexer.ts --allow-env-from-env AUTH_TOKEN,POSTGRES_CONNECTION_STRING -A ${AUTH_TOKEN}'
volumes:
- ./src:/indexer
depends_on:
Expand All @@ -43,8 +45,9 @@ services:
unruggableMemecoin-transfers-indexer:
environment:
- AUTH_TOKEN=${AUTH_TOKEN}
- POSTGRES_CONNECTION_STRING=postgresql://admin:postgres@postgres:5432/indexer
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}'
command: 'run ./indexer/unruggableMemecoin-transfers.indexer.ts --allow-env-from-env AUTH_TOKEN,POSTGRES_CONNECTION_STRING -A ${AUTH_TOKEN}'
volumes:
- ./src:/indexer
depends_on:
Expand All @@ -56,8 +59,9 @@ services:
buy-indexer:
environment:
- AUTH_TOKEN=${AUTH_TOKEN}
- POSTGRES_CONNECTION_STRING=postgresql://admin:postgres@postgres:5432/indexer
image: quay.io/apibara/sink-postgres:latest
command: 'run ./indexer/buy-token.js --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}'
command: 'run ./indexer/buy-token.ts --allow-env-from-env AUTH_TOKEN,POSTGRES_CONNECTION_STRING -A ${AUTH_TOKEN}'
volumes:
- ./src:/indexer
depends_on:
Expand All @@ -70,8 +74,9 @@ services:
sell-indexer:
environment:
- AUTH_TOKEN=${AUTH_TOKEN}
- POSTGRES_CONNECTION_STRING=postgresql://admin:postgres@postgres:5432/indexer
image: quay.io/apibara/sink-postgres:latest
command: 'run ./indexer/sell-token.js --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}'
command: 'run ./indexer/sell-token.ts --allow-env-from-env AUTH_TOKEN,POSTGRES_CONNECTION_STRING -A ${AUTH_TOKEN}'
volumes:
- ./src:/indexer
depends_on:
Expand All @@ -83,8 +88,9 @@ services:
token-indexer:
environment:
- AUTH_TOKEN=${AUTH_TOKEN}
- POSTGRES_CONNECTION_STRING=postgresql://admin:postgres@postgres:5432/indexer
image: quay.io/apibara/sink-postgres:latest
command: 'run ./indexer/token-launch.js --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}'
command: 'run ./indexer/token-launch.ts --allow-env-from-env AUTH_TOKEN,POSTGRES_CONNECTION_STRING -A ${AUTH_TOKEN}'
volumes:
- ./src:/indexer
depends_on:
Expand All @@ -96,8 +102,9 @@ services:
deploy-indexer:
environment:
- AUTH_TOKEN=${AUTH_TOKEN}
- POSTGRES_CONNECTION_STRING=postgresql://admin:postgres@postgres:5432/indexer
image: quay.io/apibara/sink-postgres:latest
command: 'run ./indexer/deploy-token.js --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}'
command: 'run ./indexer/deploy-token.ts --allow-env-from-env AUTH_TOKEN,POSTGRES_CONNECTION_STRING -A ${AUTH_TOKEN}'
volumes:
- ./src:/indexer
depends_on:
Expand Down
17 changes: 8 additions & 9 deletions apps/indexer/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ create table token_launch(
current_supply text,
liquidity_raised text,
price text,
_cursor bigint
timestamp TIMESTAMP,


_cursor bigint,
time_stamp TEXT
);

create table token_deploy(
Expand All @@ -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 TEXT


);
Expand All @@ -57,10 +55,11 @@ CREATE TABLE token_transactions (
current_supply TEXT,
liquidity_raised TEXT,
price TEXT,
protocol_fee TEXT,
amount TEXT,
timestamp TIMESTAMP,
_cursor bigint,
transaction_type TEXT NOT NULL CHECK (transaction_type IN ('buy', 'sell')),,
_cursor BIGINT,
transaction_type TEXT NOT NULL CHECK (transaction_type IN ('buy', 'sell')),
time_stamp TEXT

);

Expand Down
67 changes: 0 additions & 67 deletions apps/indexer/src/buy-token.js

This file was deleted.

89 changes: 89 additions & 0 deletions apps/indexer/src/buy-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Block, hash, uint256 } from "./deps.ts";
import { STARTING_BLOCK, LAUNCHPAD_ADDRESS } from "./constants.ts";

const filter = {
header: {
weak: true
},
events: [
{
fromAddress: LAUNCHPAD_ADDRESS.SEPOLIA,
keys: [hash.getSelectorFromName("BuyToken")],
includeReceipt: false
}
]
};

export const config = {
streamUrl: "https://sepolia.starknet.a5a.ch",
startingBlock: STARTING_BLOCK,
network: "starknet",
finality: "DATA_STATUS_ACCEPTED",
filter,
sinkType: "postgres",
sinkOptions: {
connectionString: Deno.env.get("POSTGRES_CONNECTION_STRING"),
tableName: "token_transactions"
}
};

export default function DecodeBuyToken({ header, events }: Block) {
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 [
amount_low,
amount_high,
price_low,
price_high,
protocol_fee_low,
protocol_fee_high,
last_price_low,
last_price_high,
timestamp,
quote_amount_low,
quote_amount_high
] = event.data;

const amount = uint256
.uint256ToBN({ low: amount_low, high: amount_high })
.toString();
const price = uint256
.uint256ToBN({ low: price_low, high: price_high })
.toString();
const protocol_fee = uint256
.uint256ToBN({ low: protocol_fee_low, high: protocol_fee_high })
.toString();
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 {
transfer_id,
network: "starknet-sepolia",
block_hash: blockHash,
block_number: Number(blockNumber),
block_timestamp: block_timestamp,
transaction_hash: transactionHash,
memecoin_address: token_address,
owner_address: caller,
last_price,
quote_amount,
price,
amount,
protocol_fee,
time_stamp: timestamp,
transaction_type: "buy"
};
});
}
7 changes: 0 additions & 7 deletions apps/indexer/src/constants.js

This file was deleted.

8 changes: 8 additions & 0 deletions apps/indexer/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const FACTORY_ADDRESS =
"0x01a46467a9246f45c8c340f1f155266a26a71c07bd55d36e8d1c7d0d438a2dbc";
export const STARTING_BLOCK = 140_000;
export const LAUNCHPAD_ADDRESS = {
// SEPOLIA:"0x74acb6752abb734a7b3388567429217988e02409d9bf43c5586dc2c4f8baf40",
// SEPOLIA:"0x29a532e6933a6d6f9939e59469d96b52b7c38561745331302e1a29f035e4dd0",
SEPOLIA: "0x3798921000573bfc442d8153fc088db97bd3794f5ed19ea8c0846db5378f4af"
};
Loading
Loading