commit 4a47afdc2b653d46d09f1c0aaee3c1d3c98771ae Author: Richa-iitr Date: Sun Jul 3 06:23:42 2022 +0530 Initial commit diff --git a/abis/ConnectV2SwapAggregator.json b/abis/ConnectV2SwapAggregator.json new file mode 100644 index 0000000..39dc6c6 --- /dev/null +++ b/abis/ConnectV2SwapAggregator.json @@ -0,0 +1,53 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string[]", + "name": "connectors", + "type": "string[]" + }, + { + "indexed": false, + "internalType": "string", + "name": "connectorName", + "type": "string" + }, + { + "indexed": false, + "internalType": "string", + "name": "eventName", + "type": "string" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "eventParam", + "type": "bytes" + } + ], + "name": "LogSwapAggregator", + "type": "event" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "string[]", "name": "_connectors", "type": "string[]" }, + { "internalType": "bytes[]", "name": "_datas", "type": "bytes[]" } + ], + "name": "swap", + "outputs": [ + { "internalType": "string", "name": "_eventName", "type": "string" }, + { "internalType": "bytes", "name": "_eventParam", "type": "bytes" } + ], + "stateMutability": "payable", + "type": "function" + } +] diff --git a/networks.json b/networks.json new file mode 100644 index 0000000..ff70e10 --- /dev/null +++ b/networks.json @@ -0,0 +1,7 @@ +{ + "mainnet": { + "undefined": { + "address": "0xe6aa2d277aAfBb9e19354F6f893737C3608ff995" + } + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..4de883a --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "swap-aggregator-subgraph", + "license": "UNLICENSED", + "scripts": { + "codegen": "graph codegen", + "build": "graph build", + "deploy": "graph deploy --node https://api.thegraph.com/deploy/ Richa-iitr/swap-aggregator-subgraph", + "create-local": "graph create --node http://localhost:8020/ Richa-iitr/swap-aggregator-subgraph", + "remove-local": "graph remove --node http://localhost:8020/ Richa-iitr/swap-aggregator-subgraph", + "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 Richa-iitr/swap-aggregator-subgraph" + }, + "dependencies": { + "@graphprotocol/graph-cli": "0.30.0", + "@graphprotocol/graph-ts": "0.27.0" + } +} diff --git a/schema.graphql b/schema.graphql new file mode 100644 index 0000000..d5558a1 --- /dev/null +++ b/schema.graphql @@ -0,0 +1,6 @@ +type ExampleEntity @entity { + id: ID! + count: BigInt! + connectors: [String]! # string[] + connectorName: String! # string +} diff --git a/src/connect-v-2-swap-aggregator.ts b/src/connect-v-2-swap-aggregator.ts new file mode 100644 index 0000000..3883a38 --- /dev/null +++ b/src/connect-v-2-swap-aggregator.ts @@ -0,0 +1,48 @@ +import { BigInt } from "@graphprotocol/graph-ts" +import { + ConnectV2SwapAggregator, + LogSwapAggregator +} from "../generated/ConnectV2SwapAggregator/ConnectV2SwapAggregator" +import { ExampleEntity } from "../generated/schema" + +export function handleLogSwapAggregator(event: LogSwapAggregator): void { + // Entities can be loaded from the store using a string ID; this ID + // needs to be unique across all entities of the same type + let entity = ExampleEntity.load(event.transaction.from.toHex()) + + // Entities only exist after they have been saved to the store; + // `null` checks allow to create entities on demand + if (!entity) { + entity = new ExampleEntity(event.transaction.from.toHex()) + + // Entity fields can be set using simple assignments + entity.count = BigInt.fromI32(0) + } + + // BigInt and BigDecimal math are supported + entity.count = entity.count + BigInt.fromI32(1) + + // Entity fields can be set based on event parameters + entity.connectors = event.params.connectors + entity.connectorName = event.params.connectorName + + // Entities can be written to the store with `.save()` + entity.save() + + // Note: If a handler doesn't require existing field values, it is faster + // _not_ to load the entity from the store. Instead, create it fresh with + // `new Entity(...)`, set the fields that should be updated and save the + // entity back to the store. Fields that were not set or unset remain + // unchanged, allowing for partial updates to be applied. + + // It is also possible to access smart contracts from mappings. For + // example, the contract that has emitted the event can be connected to + // with: + // + // let contract = Contract.bind(event.address) + // + // The following functions can then be called on this contract to access + // state variables and other data: + // + // - contract.name(...) +} diff --git a/subgraph.yaml b/subgraph.yaml new file mode 100644 index 0000000..944d826 --- /dev/null +++ b/subgraph.yaml @@ -0,0 +1,23 @@ +specVersion: 0.0.1 +schema: + file: ./schema.graphql +dataSources: + - kind: ethereum + name: undefined + network: mainnet + source: + address: "0xe6aa2d277aAfBb9e19354F6f893737C3608ff995" + abi: ConnectV2SwapAggregator + mapping: + kind: ethereum/events + apiVersion: 0.0.5 + language: wasm/assemblyscript + entities: + - LogSwapAggregator + abis: + - name: ConnectV2SwapAggregator + file: ./abis/ConnectV2SwapAggregator.json + eventHandlers: + - event: LogSwapAggregator(string[],string,string,bytes) + handler: handleLogSwapAggregator + file: ./src/connect-v-2-swap-aggregator.ts diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..5c5d17c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", + "include": ["src"] +}