commit 5f94d4bd88fea64bd8d0047656b9fce374c6e7b0 Author: Richa-iitr Date: Thu Oct 27 12:44:21 2022 +0530 Initial commit diff --git a/abis/FLA.json b/abis/FLA.json new file mode 100644 index 0000000..872414f --- /dev/null +++ b/abis/FLA.json @@ -0,0 +1,116 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_logic", "type": "address" }, + { "internalType": "address", "name": "admin_", "type": "address" }, + { "internalType": "bytes", "name": "_data", "type": "bytes" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "previousAdmin", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "newAdmin", + "type": "address" + } + ], + "name": "AdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "beacon", + "type": "address" + } + ], + "name": "BeaconUpgraded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { "stateMutability": "payable", "type": "fallback" }, + { + "inputs": [], + "name": "admin", + "outputs": [ + { "internalType": "address", "name": "admin_", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "newAdmin", "type": "address" } + ], + "name": "changeAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "implementation", + "outputs": [ + { + "internalType": "address", + "name": "implementation_", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + } + ], + "name": "upgradeTo", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "upgradeToAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { "stateMutability": "payable", "type": "receive" } +] diff --git a/networks.json b/networks.json new file mode 100644 index 0000000..b34bb44 --- /dev/null +++ b/networks.json @@ -0,0 +1,7 @@ +{ + "mainnet": { + "FLA": { + "address": "0x619Ad2D02dBeE6ebA3CDbDA3F98430410e892882" + } + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..96b7af6 --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "fla-fees-mainnet", + "license": "UNLICENSED", + "scripts": { + "codegen": "graph codegen", + "build": "graph build", + "deploy": "graph deploy --node https://api.thegraph.com/deploy/ Richa-iitr/fla-fees-mainnet", + "create-local": "graph create --node http://localhost:8020/ Richa-iitr/fla-fees-mainnet", + "remove-local": "graph remove --node http://localhost:8020/ Richa-iitr/fla-fees-mainnet", + "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 Richa-iitr/fla-fees-mainnet", + "test": "graph test" + }, + "dependencies": { + "@graphprotocol/graph-cli": "0.33.1", + "@graphprotocol/graph-ts": "0.27.0" + }, + "devDependencies": { "matchstick-as": "0.5.0" } +} diff --git a/schema.graphql b/schema.graphql new file mode 100644 index 0000000..3ebd0c6 --- /dev/null +++ b/schema.graphql @@ -0,0 +1,6 @@ +type ExampleEntity @entity { + id: ID! + count: BigInt! + previousAdmin: Bytes! # address + newAdmin: Bytes! # address +} diff --git a/src/fla.ts b/src/fla.ts new file mode 100644 index 0000000..63ab575 --- /dev/null +++ b/src/fla.ts @@ -0,0 +1,55 @@ +import { BigInt } from "@graphprotocol/graph-ts" +import { + FLA, + AdminChanged, + BeaconUpgraded, + Upgraded +} from "../generated/FLA/FLA" +import { ExampleEntity } from "../generated/schema" + +export function handleAdminChanged(event: AdminChanged): 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.previousAdmin = event.params.previousAdmin + entity.newAdmin = event.params.newAdmin + + // 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.admin(...) + // - contract.implementation(...) +} + +export function handleBeaconUpgraded(event: BeaconUpgraded): void {} + +export function handleUpgraded(event: Upgraded): void {} diff --git a/subgraph.yaml b/subgraph.yaml new file mode 100644 index 0000000..2d34cb6 --- /dev/null +++ b/subgraph.yaml @@ -0,0 +1,29 @@ +specVersion: 0.0.1 +schema: + file: ./schema.graphql +dataSources: + - kind: ethereum + name: FLA + network: mainnet + source: + address: "0x619Ad2D02dBeE6ebA3CDbDA3F98430410e892882" + abi: FLA + mapping: + kind: ethereum/events + apiVersion: 0.0.5 + language: wasm/assemblyscript + entities: + - AdminChanged + - BeaconUpgraded + - Upgraded + abis: + - name: FLA + file: ./abis/FLA.json + eventHandlers: + - event: AdminChanged(address,address) + handler: handleAdminChanged + - event: BeaconUpgraded(indexed address) + handler: handleBeaconUpgraded + - event: Upgraded(indexed address) + handler: handleUpgraded + file: ./src/fla.ts diff --git a/tests/fla-utils.ts b/tests/fla-utils.ts new file mode 100644 index 0000000..95f38f5 --- /dev/null +++ b/tests/fla-utils.ts @@ -0,0 +1,51 @@ +import { newMockEvent } from "matchstick-as" +import { ethereum, Address } from "@graphprotocol/graph-ts" +import { AdminChanged, BeaconUpgraded, Upgraded } from "../generated/FLA/FLA" + +export function createAdminChangedEvent( + previousAdmin: Address, + newAdmin: Address +): AdminChanged { + let adminChangedEvent = changetype(newMockEvent()) + + adminChangedEvent.parameters = new Array() + + adminChangedEvent.parameters.push( + new ethereum.EventParam( + "previousAdmin", + ethereum.Value.fromAddress(previousAdmin) + ) + ) + adminChangedEvent.parameters.push( + new ethereum.EventParam("newAdmin", ethereum.Value.fromAddress(newAdmin)) + ) + + return adminChangedEvent +} + +export function createBeaconUpgradedEvent(beacon: Address): BeaconUpgraded { + let beaconUpgradedEvent = changetype(newMockEvent()) + + beaconUpgradedEvent.parameters = new Array() + + beaconUpgradedEvent.parameters.push( + new ethereum.EventParam("beacon", ethereum.Value.fromAddress(beacon)) + ) + + return beaconUpgradedEvent +} + +export function createUpgradedEvent(implementation: Address): Upgraded { + let upgradedEvent = changetype(newMockEvent()) + + upgradedEvent.parameters = new Array() + + upgradedEvent.parameters.push( + new ethereum.EventParam( + "implementation", + ethereum.Value.fromAddress(implementation) + ) + ) + + return upgradedEvent +} diff --git a/tests/fla.test.ts b/tests/fla.test.ts new file mode 100644 index 0000000..21e2d5e --- /dev/null +++ b/tests/fla.test.ts @@ -0,0 +1,57 @@ +import { + assert, + describe, + test, + clearStore, + beforeAll, + afterAll +} from "matchstick-as/assembly/index" +import { Address } from "@graphprotocol/graph-ts" +import { ExampleEntity } from "../generated/schema" +import { AdminChanged } from "../generated/FLA/FLA" +import { handleAdminChanged } from "../src/fla" +import { createAdminChangedEvent } from "./fla-utils" + +// Tests structure (matchstick-as >=0.5.0) +// https://thegraph.com/docs/en/developer/matchstick/#tests-structure-0-5-0 + +describe("Describe entity assertions", () => { + beforeAll(() => { + let previousAdmin = Address.fromString( + "0x0000000000000000000000000000000000000001" + ) + let newAdmin = Address.fromString( + "0x0000000000000000000000000000000000000001" + ) + let newAdminChangedEvent = createAdminChangedEvent(previousAdmin, newAdmin) + handleAdminChanged(newAdminChangedEvent) + }) + + afterAll(() => { + clearStore() + }) + + // For more test scenarios, see: + // https://thegraph.com/docs/en/developer/matchstick/#write-a-unit-test + + test("ExampleEntity created and stored", () => { + assert.entityCount("ExampleEntity", 1) + + // 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default address used in newMockEvent() function + assert.fieldEquals( + "ExampleEntity", + "0xa16081f360e3847006db660bae1c6d1b2e17ec2a", + "previousAdmin", + "0x0000000000000000000000000000000000000001" + ) + assert.fieldEquals( + "ExampleEntity", + "0xa16081f360e3847006db660bae1c6d1b2e17ec2a", + "newAdmin", + "0x0000000000000000000000000000000000000001" + ) + + // More assert options: + // https://thegraph.com/docs/en/developer/matchstick/#asserts + }) +}) 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"] +}