-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,083 additions
and
277 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,6 +1,13 @@ | ||
type Gravatar @entity { | ||
type Swap @entity { | ||
id: ID! | ||
owner: Bytes! | ||
displayName: String! | ||
imageUrl: String! | ||
} | ||
sender: Bytes! # address | ||
recipient: Bytes! # address | ||
amount0: BigInt! # int256 | ||
amount1: BigInt! # int256 | ||
sqrtPriceX96: BigInt! # uint160 | ||
liquidity: BigInt! # uint128 | ||
tick: Int! # int24 | ||
blockNumber: BigInt! | ||
blockTimestamp: BigInt! | ||
transactionHash: Bytes! | ||
} |
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 |
---|---|---|
@@ -1,37 +1,54 @@ | ||
import { TypeormDatabase } from '@subsquid/typeorm-store' | ||
import { decodeHex } from '@subsquid/evm-processor' | ||
import { events } from './abi/Gravity' | ||
import { ethers } from 'ethers' | ||
import { Gravatar } from './model' | ||
import { processor, GRAVATAR_CONTRACT } from './processor' | ||
// import { TypeormDatabase } from "@subsquid/typeorm-store"; | ||
// import { decodeHex } from "@subsquid/evm-processor"; | ||
// import { events } from "./abi/SwapContract"; | ||
// import { ethers } from "ethers"; | ||
// import { Gravatar, Swap } from "./model"; | ||
// import { processor, SWAP_CONTRACT } from "./processor"; | ||
|
||
processor.run(new TypeormDatabase({supportHotBlocks: true}), async (ctx) => { | ||
const gravatars: Map<string, Gravatar> = new Map() | ||
for (const c of ctx.blocks) { | ||
for (const e of c.logs) { | ||
if (!(e.address === GRAVATAR_CONTRACT && | ||
(e.topics[0] === events.NewGravatar.topic || | ||
e.topics[0] === events.UpdatedGravatar.topic))) continue | ||
const { id, owner, displayName, imageUrl } = extractData(e) | ||
let idString = '0x' + id.toString(16) | ||
gravatars.set(idString, new Gravatar({ | ||
id: idString, | ||
owner: decodeHex(owner), | ||
displayName, | ||
imageUrl | ||
})) | ||
} | ||
} | ||
await ctx.store.upsert([...gravatars.values()]) | ||
}) | ||
// processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => { | ||
// const gravatars: Map<string, Gravatar> = new Map(); | ||
// const swaps: Map<string, Swap> = new Map(); | ||
// for (const c of ctx.blocks) { | ||
// for (const e of c.logs) { | ||
// if (!(e.address === SWAP_CONTRACT && e.topics[0] === events.Swap.topic)) | ||
// continue; | ||
// // extract information from the event | ||
// const { recipient, sender, amount0, amount1 } = extractData(e); | ||
// let idString = "0x" + id.toString(16); | ||
// // create the swap entity | ||
// gravatars.set( | ||
// idString, | ||
// new Gravatar({ | ||
// id: idString, | ||
// owner: decodeHex(owner), | ||
// displayName, | ||
// imageUrl, | ||
// }) | ||
// ); | ||
// swaps.set( | ||
// idString, | ||
// new Swap({ | ||
// id: idString, | ||
// blockNumber: c.number, | ||
// blockTimestamp: c.timestamp, | ||
// owner: decodeHex(owner), | ||
// displayName, | ||
// imageUrl, | ||
// }); | ||
// ); | ||
// } | ||
// } | ||
// await ctx.store.upsert([...swaps.values()]); | ||
// }); | ||
|
||
|
||
function extractData(evmLog: any): { id: bigint, owner: string, displayName: string, imageUrl: string} { | ||
if (evmLog.topics[0] === events.NewGravatar.topic) { | ||
return events.NewGravatar.decode(evmLog) | ||
} | ||
if (evmLog.topics[0] === events.UpdatedGravatar.topic) { | ||
return events.UpdatedGravatar.decode(evmLog) | ||
} | ||
throw new Error('Unsupported topic') | ||
} | ||
// function extractData(evmLog: any): { | ||
// id: bigint; | ||
// owner: string; | ||
// displayName: string; | ||
// imageUrl: string; | ||
// } { | ||
// if (evmLog.topics[0] === events.Swap.topic) { | ||
// return events.Swap.decode(evmLog); | ||
// } | ||
// throw new Error("Unsupported topic"); | ||
// } |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./gravatar.model" | ||
export * from "./swap.model" |
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,42 @@ | ||
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_} from "typeorm" | ||
import * as marshal from "./marshal" | ||
|
||
@Entity_() | ||
export class Swap { | ||
constructor(props?: Partial<Swap>) { | ||
Object.assign(this, props) | ||
} | ||
|
||
@PrimaryColumn_() | ||
id!: string | ||
|
||
@Column_("bytea", {nullable: false}) | ||
sender!: Uint8Array | ||
|
||
@Column_("bytea", {nullable: false}) | ||
recipient!: Uint8Array | ||
|
||
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false}) | ||
amount0!: bigint | ||
|
||
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false}) | ||
amount1!: bigint | ||
|
||
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false}) | ||
sqrtPriceX96!: bigint | ||
|
||
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false}) | ||
liquidity!: bigint | ||
|
||
@Column_("int4", {nullable: false}) | ||
tick!: number | ||
|
||
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false}) | ||
blockNumber!: bigint | ||
|
||
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false}) | ||
blockTimestamp!: bigint | ||
|
||
@Column_("bytea", {nullable: false}) | ||
transactionHash!: Uint8Array | ||
} |
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 |
---|---|---|
@@ -1,21 +1,19 @@ | ||
import { EvmBatchProcessor} from '@subsquid/evm-processor' | ||
import { events } from './abi/Gravity' | ||
import { lookupArchive } from '@subsquid/archive-registry' | ||
// import { EvmBatchProcessor } from "@subsquid/evm-processor"; | ||
// import { events } from "./abi/SwapContract"; | ||
// import { lookupArchive } from "@subsquid/archive-registry"; | ||
|
||
export const GRAVATAR_CONTRACT = '0x2E645469f354BB4F5c8a05B3b30A929361cf77eC'.toLowerCase() | ||
|
||
export const processor = new EvmBatchProcessor() | ||
.setDataSource({ | ||
archive: lookupArchive('eth-mainnet'), | ||
chain: 'https://rpc.ankr.com/eth' | ||
}) | ||
.setBlockRange({ from: 6175243 }) | ||
.setFinalityConfirmation(75) | ||
.addLog({ | ||
address: [ GRAVATAR_CONTRACT ], | ||
topic0: [ | ||
events.NewGravatar.topic, | ||
events.UpdatedGravatar.topic, | ||
], | ||
}) | ||
// export const SWAP_CONTRACT = | ||
// "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640".toLowerCase(); | ||
|
||
// export const processor = new EvmBatchProcessor() | ||
// .setDataSource({ | ||
// archive: lookupArchive("eth-mainnet"), | ||
// chain: | ||
// "https://ethereum-mainnet.core.chainstack.com/4f684a0bcb02b58f9a2fd403d913783b", | ||
// }) | ||
// .setBlockRange({ from: 12_376_729 }) | ||
// .setFinalityConfirmation(75) | ||
// .addLog({ | ||
// address: [SWAP_CONTRACT], | ||
// topic0: [events.Swap.topic], | ||
// }); |