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

Feat: Indexer + Launchpad + Solidity #19

Merged
merged 11 commits into from
Aug 17, 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
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "solidity/solidity_contracts/lib/kakarot-lib"]
path = solidity/solidity_contracts/lib/kakarot-lib
url = https://github.com/kkrt-labs/kakarot-lib
[submodule "solidity/solidity_contracts/lib/forge-std"]
path = solidity/solidity_contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
14 changes: 14 additions & 0 deletions apps/indexer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Notice that the base image is build from scratch (not an OS like Ubuntu),
# so the binary is in a location that depends on the build.
# For this reason we stick to a specific version and architecture.
#
# When updating the image you also need to update the entrypoint below.
#
# - docker image pull quay.io/apibara/sink-postgres:0.7.0-x86_64
# - docker image inspect quay.io/apibara/sink-postgres:0.7.0-x86_64 | jq '.[].Config.Entrypoint'
FROM quay.io/apibara/sink-postgres:0.7.0-x86_64

WORKDIR /app
COPY ./src/* /app

ENTRYPOINT ["/nix/store/rh1g8pb7wfnyr527jfmkkc5lm3sa1f0l-apibara-sink-postgres-0.7.0/bin/apibara-sink-postgres"]
19 changes: 19 additions & 0 deletions apps/indexer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Setup

## Install Apibara

## Install Postgres and Init the tables

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

# Test

unrugmeme_deploy

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


```
58 changes: 58 additions & 0 deletions apps/indexer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: '3.8'

services:
postgres:
image: postgres:latest
environment:
POSTGRES_DB: indexer
POSTGRES_USER: admin
POSTGRES_PASSWORD: password
ports:
- '5432:5432'
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
networks:
- backend

unruggableMemecoin-deploy-indexer:
environment:
- AUTH_TOKEN=${AUTH_TOKEN}
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}'
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.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.ts --connection-string postgresql://admin:password@postgres:5432/indexer -A ${AUTH_TOKEN}'
volumes:
- ./src:/indexer
depends_on:
- postgres
networks:
- backend
restart: on-failure

networks:
backend:
driver: bridge
19 changes: 19 additions & 0 deletions apps/indexer/envs.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Secret
metadata:
namespace: default
name: apibara-api-key
stringData:
production: dna_XXX # replace with your production key

---
apiVersion: v1
kind: Secret
metadata:
namespace: default
name: database-connection-string
stringData:
production: your_postgres_connection_string # replace with postgres connection string

# To apply :
# kubectl apply -f envs.yaml
89 changes: 89 additions & 0 deletions apps/indexer/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
create table unrugmeme_transfers(
network text,
block_hash text,
block_number bigint,
block_timestamp timestamp,
transaction_hash text,
transfer_id text unique primary key,
from_address text,
to_address text,
memecoin_address text,
amount text,
created_at timestamp default current_timestamp,
_cursor bigint
);

create table unrugmeme_deploy(
network text,
block_hash text,
block_number bigint,
block_timestamp timestamp,
transaction_hash text,
memecoin_address text unique primary key,
owner_address text,
name text,
symbol text,
initial_supply text,
created_at timestamp default current_timestamp,
_cursor bigint
);

create table unrugmeme_launch(
network text,
block_hash text,
block_number bigint,
block_timestamp timestamp,
transaction_hash text,
memecoin_address text unique primary key,
quote_token text,
exchange_name text,
created_at timestamp default current_timestamp,
_cursor bigint
);


create table token_launch(
network text,
block_hash text,
block_number bigint,
block_timestamp timestamp,
transaction_hash text,
memecoin_address text unique primary key,
quote_token text,
exchange_name text,
created_at timestamp default current_timestamp,
_cursor bigint
);



create table token_deploy(
network text,
block_hash text,
block_number bigint,
block_timestamp timestamp,
transaction_hash text,
memecoin_address text unique primary key,
owner_address text,
name text,
symbol text,
initial_supply text,
created_at timestamp default current_timestamp,
_cursor bigint
);


create table buy_token(
network text,
block_hash text,
block_number bigint,
block_timestamp timestamp,
transaction_hash text,
memecoin_address text unique primary key,
owner_address text,
last_price text,
initial_supply text,
created_at timestamp default current_timestamp,
_cursor bigint
);

92 changes: 92 additions & 0 deletions apps/indexer/pump-buy-coin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// import { Block, Config, hash, shortString, uint256, NetworkOptions, Console } from './src/deps.js'
// import { FACTORY_ADDRESS, LAUNCHPAD_ADDRESS, STARTING_BLOCK } from './src/constants.js'
export const FACTORY_ADDRESS = '0x01a46467a9246f45c8c340f1f155266a26a71c07bd55d36e8d1c7d0d438a2dbc'
export const STARTING_BLOCK = 615556


export const LAUNCHPAD_ADDRESS = {
SEPOLIA:"0x74acb6752abb734a7b3388567429217988e02409d9bf43c5586dc2c4f8baf40",
}
import { hash, uint256 } from "https://esm.run/[email protected]";
import { formatUnits } from "https://esm.run/[email protected]";


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: "console",
sinkOptions: {},
// sinkType: 'postgres',
// sinkOptions: {
// connectionString: '',
// tableName: 'buy_token',
// },
}

export default function DecodeBuyToken({ header, events }) {
const { blockNumber, blockHash, timestamp } = header

return (events ?? []).map(({ event, transaction }) => {
if (!event.data) return

const transactionHash = transaction.meta.hash


return {
transactionHash,
block_hash: blockHash,
block_number: +blockNumber,
block_timestamp: timestamp,
transaction_hash: transactionHash,
transfer_id: transferId,
from_address: fromAddress,
}

// const [caller, token_address,
// amount_low, amount_high,
// price_low, price_high,
// protocol_fee_low, protocol_fee_high,

// initial_supply_low, initial_supply_high,
// // total_supply_low, total_supply_high,

// ] = event.data;
// const amount = uint256.uint256ToBN({ low: amount_low, high: amount_high }).toString()
// const initial_supply = uint256.uint256ToBN({ low: initial_supply_low, high: initial_supply_high }).toString()
// // const total_supply = uint256.uint256ToBN({ low: total_supply_low, high: total_supply_high }).toString()
// const price = uint256.uint256ToBN({ low: price_low, high: price_higt }).toString()
// const protocol_fee = uint256.uint256ToBN({ low: protocol_fee_low, high: protocol_fee_high }).toString()

// return {
// network: 'starknet-sepolia',
// block_hash: blockHash,
// block_number: Number(blockNumber),
// block_timestamp: timestamp,
// transaction_hash: transactionHash,
// memecoin_address: token_address,
// owner_address: caller,
// initial_supply: initial_supply,
// // total_supply: total_supply,
// price:price,
// protocol_fee:protocol_fee,
// timestamp: new Date().toISOString(),
// created_at: new Date().toISOString(),
// }
})
}
5 changes: 5 additions & 0 deletions apps/indexer/src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const FACTORY_ADDRESS = '0x01a46467a9246f45c8c340f1f155266a26a71c07bd55d36e8d1c7d0d438a2dbc'
export const STARTING_BLOCK = 100_000
export const LAUNCHPAD_ADDRESS = {
SEPOLIA:"0x74acb6752abb734a7b3388567429217988e02409d9bf43c5586dc2c4f8baf40",
}
6 changes: 6 additions & 0 deletions apps/indexer/src/deps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { ec, hash, uint256, shortString } from 'https://esm.sh/[email protected]'
export { formatUnits } from 'https://esm.sh/[email protected]'

export { Block, FieldElement, Filter } from 'https://esm.sh/@apibara/[email protected]/starknet'
export { Config, NetworkOptions } from "https://esm.sh/@apibara/indexer";
export { Console } from "https://esm.sh/@apibara/indexer/sink/console";
Loading
Loading