-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unruggable memecoins launch and transfers indexers (#250)
Co-authored-by: 0xChqrles <[email protected]> Co-authored-by: Uğur Eren <[email protected]>
- Loading branch information
1 parent
24c6e49
commit 366cec5
Showing
8 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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-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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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_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 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { ec, hash, uint256, shortString } from 'https://esm.sh/[email protected]' | ||
export { formatUnits } from 'https://esm.sh/[email protected]' | ||
|
||
export type { Block, FieldElement, Filter } from 'https://esm.sh/@apibara/[email protected]/starknet' |
52 changes: 52 additions & 0 deletions
52
packages/indexers/src/unruggableMemecoin-launch.indexer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Block, hash, shortString } from './deps.ts' | ||
import { FACTORY_ADDRESS, STARTING_BLOCK } from './unruggableMemecoin.ts' | ||
|
||
const filter = { | ||
header: { | ||
weak: true, | ||
}, | ||
events: [ | ||
{ | ||
fromAddress: FACTORY_ADDRESS, | ||
keys: [hash.getSelectorFromName('MemecoinLaunched')], | ||
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_launch', | ||
}, | ||
} | ||
|
||
export default function DecodeUnruggableMemecoinLaunch({ header, events }: Block) { | ||
const { blockNumber, blockHash, timestamp } = header! | ||
|
||
return (events ?? []).map(({ event, transaction }) => { | ||
const transactionHash = transaction.meta.hash | ||
|
||
const [memecoin_address, quote_token, exchange_name] = event.data | ||
|
||
const exchange_name_decoded = shortString.shortString(exchange_name) | ||
|
||
return { | ||
network: 'starknet-mainnet', | ||
block_hash: blockHash, | ||
block_number: +blockNumber, | ||
block_timestamp: timestamp, | ||
transaction_hash: transactionHash, | ||
memecoin_address: memecoin_address, | ||
quote_token: quote_token, | ||
exchange_name: exchange_name_decoded, | ||
created_at: new Date().toISOString(), | ||
} | ||
}) | ||
} |
69 changes: 69 additions & 0 deletions
69
packages/indexers/src/unruggableMemecoin-transfers.indexer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Block, hash, uint256 } from './deps.ts' | ||
import { FACTORY_ADDRESS, STARTING_BLOCK } from './unruggableMemecoin.ts' | ||
|
||
export const config = { | ||
filter: { | ||
header: { weak: true }, | ||
events: [ | ||
{ | ||
fromAddress: FACTORY_ADDRESS, | ||
keys: [hash.getSelectorFromName('MemecoinLaunched')], | ||
includeReceipt: false, | ||
}, | ||
], | ||
}, | ||
streamUrl: 'https://mainnet.starknet.a5a.ch', | ||
startingBlock: STARTING_BLOCK, | ||
network: 'starknet', | ||
finality: 'DATA_STATUS_ACCEPTED', | ||
sinkType: 'postgres', | ||
sinkOptions: { | ||
connectionString: '', | ||
tableName: 'unrugmeme_transfers', | ||
}, | ||
} | ||
|
||
export function factory({ header, events }) { | ||
const launchEvents = (events ?? []).map(({ event }) => { | ||
const memecoin_address = event.data[0] | ||
return { | ||
fromAddress: memecoin_address, | ||
keys: [hash.getSelectorFromName('Transfer')], | ||
includeReceipt: false, | ||
} | ||
}) | ||
|
||
return { | ||
filter: { | ||
header: { weak: true }, | ||
events: launchEvents, | ||
}, | ||
} | ||
} | ||
|
||
export default function DecodeUnruggableMemecoinLaunch({ header, events }: Block) { | ||
const { blockNumber, blockHash, timestamp } = header! | ||
|
||
return (events ?? []).map(({ event, transaction }) => { | ||
const transactionHash = transaction.meta.hash | ||
const transferId = `${transactionHash}_${event.index ?? 0}` | ||
const fromAddress = event.keys[1] | ||
const toAddress = event.keys[2] | ||
const amount = uint256.uint256ToBN({ low: event.data[0], high: event.data[1] }) | ||
const memecoin_address = event.fromAddress | ||
|
||
return { | ||
network: 'starknet-mainnet', | ||
block_hash: blockHash, | ||
block_number: +blockNumber, | ||
block_timestamp: timestamp, | ||
transaction_hash: transactionHash, | ||
transfer_id: transferId, | ||
from_address: fromAddress, | ||
to_address: toAddress, | ||
memecoin_address: memecoin_address, | ||
amount: amount.toString(10), | ||
created_at: new Date().toISOString(), | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const FACTORY_ADDRESS = '0x01a46467a9246f45c8c340f1f155266a26a71c07bd55d36e8d1c7d0d438a2dbc' | ||
export const STARTING_BLOCK = 615556 |