From 968994e0250244594c07c993499b5a47eb000085 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:23:15 +0800 Subject: [PATCH] Featuring Celo Alfajores (#231) Co-authored-by: jamesbayly <46693720+jamesbayly@users.noreply.github.com> Co-authored-by: James Bayly --- .github/scripts/ci.package.json | 1 + .../.github/workflows/cli-deploy.yml | 33 +++ .../.github/workflows/pr.yml | 24 ++ .../workflows/scripts/publish-deploy.sh | 14 ++ .../celo-alfajores-testnet-starter/.gitignore | 60 +++++ .../celo-alfajores-testnet-starter/LICENSE | 21 ++ .../celo-alfajores-testnet-starter/README.md | 90 +++++++ .../abis/erc20.abi.json | 222 ++++++++++++++++++ .../docker-compose.yml | 67 ++++++ .../docker/load-extensions.sh | 6 + .../docker/pg-Dockerfile | 9 + .../package.json | 34 +++ .../celo-alfajores-testnet-starter/project.ts | 89 +++++++ .../schema.graphql | 21 ++ .../src/index.ts | 2 + .../src/mappings/mappingHandlers.ts | 37 +++ .../src/test/mappingHandlers.test.ts | 12 + .../tsconfig.json | 16 ++ 18 files changed, 758 insertions(+) create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/.github/workflows/cli-deploy.yml create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/.github/workflows/pr.yml create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/.github/workflows/scripts/publish-deploy.sh create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/.gitignore create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/LICENSE create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/README.md create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/abis/erc20.abi.json create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/docker-compose.yml create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/docker/load-extensions.sh create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/docker/pg-Dockerfile create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/package.json create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/project.ts create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/schema.graphql create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/src/index.ts create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/src/mappings/mappingHandlers.ts create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/src/test/mappingHandlers.test.ts create mode 100644 Celo Alfajores/celo-alfajores-testnet-starter/tsconfig.json diff --git a/.github/scripts/ci.package.json b/.github/scripts/ci.package.json index e152538c..ed2289be 100644 --- a/.github/scripts/ci.package.json +++ b/.github/scripts/ci.package.json @@ -89,6 +89,7 @@ "Now Chain", "Kakarot Starknet", "0G Newton Testnet", + "Celo Alfajores", "Cyber", "DFK Chain", "Dogechain", diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/.github/workflows/cli-deploy.yml b/Celo Alfajores/celo-alfajores-testnet-starter/.github/workflows/cli-deploy.yml new file mode 100644 index 00000000..5edba7c0 --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/.github/workflows/cli-deploy.yml @@ -0,0 +1,33 @@ +name: "CLI deploy" + +on: + workflow_dispatch: + inputs: + projectName: + description: "Project name" + required: true + type: string +jobs: + deploy: + name: CLI Deploy + runs-on: ubuntu-latest + environment: + name: DEPLOYMENT + env: + SUBQL_ACCESS_TOKEN: ${{ secrets.SUBQL_ACCESS_TOKEN }} + steps: + - uses: actions/checkout@v2 + - name: Setup Node.js environment + uses: actions/setup-node@v2 + with: + node-version: 16 + - run: yarn + - name: Codegen + run: yarn codegen + - name: Version + run: npx subql --version + - name: repo + run: echo ${{github.repository}} + - name: Publish and Deploy + run: | + sh .github/workflows/scripts/publish-deploy.sh -o ${{github.repository}} -p ${{github.event.inputs.projectName}} diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/.github/workflows/pr.yml b/Celo Alfajores/celo-alfajores-testnet-starter/.github/workflows/pr.yml new file mode 100644 index 00000000..7a3166c7 --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/.github/workflows/pr.yml @@ -0,0 +1,24 @@ +name: PR +on: + pull_request: + paths-ignore: + - ".github/workflows/**" +jobs: + pr: + name: pr + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Node.js environment + uses: actions/setup-node@v2 + with: + node-version: 16 + - run: yarn + - name: Codegen + run: yarn codegen + - name: Build + run: yarn build + - name: Install subql-node-ethereum + run: yarn global add @subql/node-ethereum + - name: Run tests with Subquery Node + run: subql-node-ethereum test -f ${{ github.workspace }} diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/.github/workflows/scripts/publish-deploy.sh b/Celo Alfajores/celo-alfajores-testnet-starter/.github/workflows/scripts/publish-deploy.sh new file mode 100644 index 00000000..adae267d --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/.github/workflows/scripts/publish-deploy.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +while getopts p:o: flag +do + case "${flag}" in + p) PROJECTNAME=${OPTARG};; + o) ORG=${OPTARG};; + *) echo "Usage: $0 [-p projectname] [-o org]" && exit 1;; + esac +done + +IPFSCID=$(npx subql publish -o -f .) + +npx subql deployment:deploy -d --ipfsCID="$IPFSCID" --projectName="${PROJECTNAME}" --org="${ORG%/*}" \ No newline at end of file diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/.gitignore b/Celo Alfajores/celo-alfajores-testnet-starter/.gitignore new file mode 100644 index 00000000..53b19635 --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/.gitignore @@ -0,0 +1,60 @@ +# These are some examples of commonly ignored file patterns. +# You should customize this list as applicable to your project. +# Learn more about .gitignore: +# https://www.atlassian.com/git/tutorials/saving-changes/gitignore + +# Node artifact files +node_modules/ +dist/ + +# lock files +yarn.lock +package-lock.json + +# Compiled Java class files +*.class + +# Compiled Python bytecode +*.py[cod] + +# Log files +*.log + +# Package files +*.jar + +# Generated files +target/ +dist/ +src/types +project.yaml + +# JetBrains IDE +.idea/ + +# Unit test reports +TEST*.xml + +# Generated by MacOS +.DS_Store + +# Generated by Windows +Thumbs.db + +# Applications +*.app +*.exe +*.war + +# Large media files +*.mp4 +*.tiff +*.avi +*.flv +*.mov +*.wmv + +.data +.yarn + +.DS_Store diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/LICENSE b/Celo Alfajores/celo-alfajores-testnet-starter/LICENSE new file mode 100644 index 00000000..f168fbe1 --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/LICENSE @@ -0,0 +1,21 @@ +MIT LICENSE + +Copyright 2020-2024 SubQuery Pte Ltd authors & contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/README.md b/Celo Alfajores/celo-alfajores-testnet-starter/README.md new file mode 100644 index 00000000..7fbdc251 --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/README.md @@ -0,0 +1,90 @@ +# SubQuery - Example Project for Celo Alfajores Testnet + +[SubQuery](https://subquery.network) is a fast, flexible, and reliable open-source data indexer that provides you with custom APIs for your web3 project across all of our supported networks. To learn about how to get started with SubQuery, [visit our docs](https://academy.subquery.network). + +**This SubQuery project indexes all transfers and approval events for the MyTether USD (`0x5C68B64d52B651916796f195fb776cB49bAa12d8`) on Celo Alfajores Testnet** + +## Start + +First, install SubQuery CLI globally on your terminal by using NPM `npm install -g @subql/cli` + +You can either clone this GitHub repo, or use the `subql` CLI to bootstrap a clean project in the network of your choosing by running `subql init` and following the prompts. + +Don't forget to install dependencies with `npm install` or `yarn install`! + +## Editing your SubQuery project + +Although this is a working example SubQuery project, you can edit the SubQuery project by changing the following files: + +- The project manifest in `project.yaml` defines the key project configuration and mapping handler filters +- The GraphQL Schema (`schema.graphql`) defines the shape of the resulting data that you are using SubQuery to index +- The Mapping functions in `src/mappings/` directory are typescript functions that handle transformation logic + +SubQuery supports various layer-1 blockchain networks and provides [dedicated quick start guides](https://academy.subquery.network/quickstart/quickstart.html) as well as [detailed technical documentation](https://academy.subquery.network/build/introduction.html) for each of them. + +## Run your project + +_If you get stuck, find out how to get help below._ + +The simplest way to run your project is by running `yarn dev` or `npm run-script dev`. This does all of the following: + +1. `yarn codegen` - Generates types from the GraphQL schema definition and contract ABIs and saves them in the `/src/types` directory. This must be done after each change to the `schema.graphql` file or the contract ABIs +2. `yarn build` - Builds and packages the SubQuery project into the `/dist` directory +3. `docker-compose pull && docker-compose up` - Runs a Docker container with an indexer, PostgeSQL DB, and a query service. This requires [Docker to be installed](https://docs.docker.com/engine/install) and running locally. The configuration for this container is set from your `docker-compose.yml` + +You can observe the three services start, and once all are running (it may take a few minutes on your first start), please open your browser and head to [http://localhost:3000](http://localhost:3000) - you should see a GraphQL playground showing with the schemas ready to query. [Read the docs for more information](https://academy.subquery.network/run_publish/run.html) or [explore the possible service configuration for running SubQuery](https://academy.subquery.network/run_publish/references.html). + +## Query your project + +For this project, you can try to query with the following GraphQL code to get a taste of how it works. + +```graphql +{ + query { + transfers(first: 5, orderBy: VALUE_DESC) { + totalCount + nodes { + id + blockHeight + from + to + value + contractAddress + } + } + } + approvals(first: 5, orderBy: BLOCK_HEIGHT_DESC) { + nodes { + id + blockHeight + owner + spender + value + contractAddress + } + } +} +``` + +You can explore the different possible queries and entities to help you with GraphQL using the documentation draw on the right. + +## Publish your project + +SubQuery is open-source, meaning you have the freedom to run it in the following three ways: + +- Locally on your own computer (or a cloud provider of your choosing), [view the instructions on how to run SubQuery Locally](https://academy.subquery.network/run_publish/run.html) +- By publishing it to our enterprise-level [Managed Service](https://managedservice.subquery.network), where we'll host your SubQuery project in production ready services for mission critical data with zero-downtime blue/green deployments. We even have a generous free tier. [Find out how](https://academy.subquery.network/run_publish/publish.html) +- By publishing it to the decentralised [SubQuery Network](https://app.subquery.network), the most open, performant, reliable, and scalable data service for dApp developers. The SubQuery Network indexes and services data to the global community in an incentivised and verifiable way + +## What Next? + +Take a look at some of our advanced features to take your project to the next level! + +- [**Multi-chain indexing support**](https://academy.subquery.network/build/multi-chain.html) - SubQuery allows you to index data from across different layer-1 networks into the same database, this allows you to query a single endpoint to get data for all supported networks. +- [**Dynamic Data Sources**](https://academy.subquery.network/build/dynamicdatasources.html) - When you want to index factory contracts, for example on a DEX or generative NFT project. +- [**Project Optimisation Advice**](https://academy.subquery.network/build/optimisation.html) - Some common tips on how to tweak your project to maximise performance. +- [**GraphQL Subscriptions**](https://academy.subquery.network/run_publish/subscription.html) - Build more reactive front end applications that subscribe to changes in your SubQuery project. + +## Need Help? + +The fastest way to get support is by [searching our documentation](https://academy.subquery.network), or by [joining our discord](https://discord.com/invite/subquery) and messaging us in the `#technical-support` channel. diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/abis/erc20.abi.json b/Celo Alfajores/celo-alfajores-testnet-starter/abis/erc20.abi.json new file mode 100644 index 00000000..405d6b36 --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/abis/erc20.abi.json @@ -0,0 +1,222 @@ +[ + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [ + { + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_spender", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_from", + "type": "address" + }, + { + "name": "_to", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [ + { + "name": "", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_owner", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "name": "balance", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [ + { + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_to", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_owner", + "type": "address" + }, + { + "name": "_spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "payable": true, + "stateMutability": "payable", + "type": "fallback" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "from", + "type": "address" + }, + { + "indexed": true, + "name": "to", + "type": "address" + }, + { + "indexed": false, + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + } +] diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/docker-compose.yml b/Celo Alfajores/celo-alfajores-testnet-starter/docker-compose.yml new file mode 100644 index 00000000..4ddd9bc3 --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/docker-compose.yml @@ -0,0 +1,67 @@ +version: "3" + +services: + postgres: + build: + context: . + dockerfile: ./docker/pg-Dockerfile + ports: + - 5432:5432 + volumes: + - .data/postgres:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: postgres + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + + subquery-node: + image: subquerynetwork/subql-node-ethereum:latest + depends_on: + "postgres": + condition: service_healthy + restart: unless-stopped + environment: + DB_USER: postgres + DB_PASS: postgres + DB_DATABASE: postgres + DB_HOST: postgres + DB_PORT: 5432 + volumes: + - ./:/app + command: + - ${SUB_COMMAND} # set SUB_COMMAND env variable to "test" to run tests + - -f=/app + - --db-schema=app + - --workers=4 + - --batch-size=30 + - --unfinalized-blocks=true + + healthcheck: + test: ["CMD", "curl", "-f", "http://subquery-node:3000/ready"] + interval: 3s + timeout: 5s + retries: 10 + + graphql-engine: + image: subquerynetwork/subql-query:latest + ports: + - 3000:3000 + depends_on: + "postgres": + condition: service_healthy + "subquery-node": + condition: service_healthy + restart: always + environment: + DB_USER: postgres + DB_PASS: postgres + DB_DATABASE: postgres + DB_HOST: postgres + DB_PORT: 5432 + command: + - --name=app + - --playground + - --indexer=http://subquery-node:3000 diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/docker/load-extensions.sh b/Celo Alfajores/celo-alfajores-testnet-starter/docker/load-extensions.sh new file mode 100644 index 00000000..7f5d0206 --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/docker/load-extensions.sh @@ -0,0 +1,6 @@ + +#!/bin/sh + +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <=3.0.0", + }, + query: { + name: "@subql/query", + version: "*", + }, + }, + schema: { + file: "./schema.graphql", + }, + network: { + /** + * chainId is the EVM Chain ID, for Celo Alfajores this is 44787 + * https://chainlist.org/chain/44787 + */ + chainId: "44787", + /** + * These endpoint(s) should be public non-pruned archive node + * We recommend providing more than one endpoint for improved reliability, performance, and uptime + * Public nodes may be rate limited, which can affect indexing speed + * When developing your project we suggest getting a private API key + * If you use a rate limited endpoint, adjust the --batch-size and --workers parameters + * These settings can be found in your docker-compose.yaml, they will slow indexing but prevent your project being rate limited + */ + endpoint: ["https://alfajores-forno.celo-testnet.org,wss://alfajores-forno.celo-testnet.org/ws"], + }, + dataSources: [ + { + kind: EthereumDatasourceKind.Runtime, + startBlock: 26160957, + options: { + abi: "erc20", + // This is the contract address for MyTether USD + address: "0x5C68B64d52B651916796f195fb776cB49bAa12d8", + }, + assets: new Map([["erc20", { file: "./abis/erc20.abi.json" }]]), + mapping: { + file: "./dist/index.js", + handlers: [ + { + kind: EthereumHandlerKind.Call, // We use ethereum handlers since Celo Alfajores Testnet is EVM-compatible + handler: "handleTransaction", + filter: { + /** + * The function can either be the function fragment or signature + * function: '0x095ea7b3' + * function: '0x7ff36ab500000000000000000000000000000000000000000000000000000000' + */ + function: "approve(address spender, uint256 amount)", + }, + }, + { + kind: EthereumHandlerKind.Event, + handler: "handleLog", + filter: { + /** + * Follows standard log filters https://docs.ethers.io/v5/concepts/events/ + * address: "0x60781C2586D68229fde47564546784ab3fACA982" + */ + topics: [ + "Transfer(address indexed from, address indexed to, uint256 amount)", + ], + }, + }, + ], + }, + }, + ], + repository: "https://github.com/subquery/ethereum-subql-starter", +}; + +// Must set default to the project instance +export default project; diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/schema.graphql b/Celo Alfajores/celo-alfajores-testnet-starter/schema.graphql new file mode 100644 index 00000000..dc4b318c --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/schema.graphql @@ -0,0 +1,21 @@ +# To improve query performance, we strongly suggest adding indexes to any field that you plan to filter or sort by +# Add the `@index` or `@index(unique: true)` annotation after any non-key field +# https://academy.subquery.network/build/graphql.html#indexing-by-non-primary-key-field + +type Transfer @entity { + id: ID! # Transaction hash + blockHeight: BigInt + to: String! + from: String! + value: BigInt! + contractAddress: String! +} + +type Approval @entity { + id: ID! # Transaction hash + blockHeight: BigInt + owner: String! + spender: String! + value: BigInt! + contractAddress: String! +} diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/src/index.ts b/Celo Alfajores/celo-alfajores-testnet-starter/src/index.ts new file mode 100644 index 00000000..fb59776f --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/src/index.ts @@ -0,0 +1,2 @@ +//Exports all handler functions +export * from "./mappings/mappingHandlers"; diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/src/mappings/mappingHandlers.ts b/Celo Alfajores/celo-alfajores-testnet-starter/src/mappings/mappingHandlers.ts new file mode 100644 index 00000000..d5a6ade6 --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/src/mappings/mappingHandlers.ts @@ -0,0 +1,37 @@ +import { Approval, Transfer } from "../types"; +import { + ApproveTransaction, + TransferLog, +} from "../types/abi-interfaces/Erc20Abi"; +import assert from "assert"; + +export async function handleLog(log: TransferLog): Promise { + logger.info(`New transfer transaction log at block ${log.blockNumber}`); + assert(log.args, "No log.args"); + + const transaction = Transfer.create({ + id: log.transactionHash, + blockHeight: BigInt(log.blockNumber), + to: log.args.to, + from: log.args.from, + value: log.args.value.toBigInt(), + contractAddress: log.address, + }); + + await transaction.save(); +} + +export async function handleTransaction(tx: ApproveTransaction): Promise { + logger.info(`New Approval transaction at block ${tx.blockNumber}`); + assert(tx.args, "No tx.args"); + + const approval = Approval.create({ + id: tx.hash, + owner: tx.from, + spender: await tx.args[0], + value: BigInt(await tx.args[1].toString()), + contractAddress: tx.to || "", + }); + + await approval.save(); +} diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/src/test/mappingHandlers.test.ts b/Celo Alfajores/celo-alfajores-testnet-starter/src/test/mappingHandlers.test.ts new file mode 100644 index 00000000..42f41c3f --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/src/test/mappingHandlers.test.ts @@ -0,0 +1,12 @@ +import { subqlTest } from "@subql/testing"; + +/* +// https://academy.subquery.network/build/testing.html +subqlTest( + "testName", // test name + 1000003, // block height to process + [], // dependent entities + [], // expected entities + "handleEvent" //handler name +); +*/ diff --git a/Celo Alfajores/celo-alfajores-testnet-starter/tsconfig.json b/Celo Alfajores/celo-alfajores-testnet-starter/tsconfig.json new file mode 100644 index 00000000..5dee9796 --- /dev/null +++ b/Celo Alfajores/celo-alfajores-testnet-starter/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "esModuleInterop": true, + "declaration": true, + "importHelpers": true, + "resolveJsonModule": true, + "module": "commonjs", + "outDir": "dist", + "rootDir": "src", + "target": "es2018", + "strict": true, + }, + "include": ["src/**/*", "node_modules/@subql/types-core/dist/global.d.ts"], +}