From a2de036f8b6c65f4050ff006793d7beab7b8dc6c Mon Sep 17 00:00:00 2001 From: brokenomics Date: Sun, 27 Mar 2022 15:07:29 -0700 Subject: [PATCH] Initial commit --- abis/NewOrder.json | 383 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 16 ++ schema.graphql | 6 + src/mapping.ts | 78 +++++++++ subgraph.yaml | 35 +++++ tsconfig.json | 4 + 6 files changed, 522 insertions(+) create mode 100644 abis/NewOrder.json create mode 100644 package.json create mode 100644 schema.graphql create mode 100644 src/mapping.ts create mode 100644 subgraph.yaml create mode 100644 tsconfig.json diff --git a/abis/NewOrder.json b/abis/NewOrder.json new file mode 100644 index 0000000..9b2d8d3 --- /dev/null +++ b/abis/NewOrder.json @@ -0,0 +1,383 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "previousAdminRole", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "newAdminRole", + "type": "bytes32" + } + ], + "name": "RoleAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [], + "name": "DEFAULT_ADMIN_ROLE", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MINTER_ROLE", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "burn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "burnFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" } + ], + "name": "getRoleAdmin", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "getRoleMember", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" } + ], + "name": "getRoleMemberCount", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "grantRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "hasRole", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "addedValue", "type": "uint256" } + ], + "name": "increaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "string", "name": "name", "type": "string" }, + { "internalType": "string", "name": "symbol", "type": "string" }, + { "internalType": "uint8", "name": "decimals", "type": "uint8" }, + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "mint", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "nonces", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "renounceRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "role", "type": "bytes32" }, + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "revokeRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "sender", "type": "address" }, + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/package.json b/package.json new file mode 100644 index 0000000..a746fdd --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "new-order-avalanche", + "license": "UNLICENSED", + "scripts": { + "codegen": "graph codegen", + "build": "graph build", + "deploy": "graph deploy --node https://api.thegraph.com/deploy/ brokenomics/new-order-avalanche", + "create-local": "graph create --node http://localhost:8020/ brokenomics/new-order-avalanche", + "remove-local": "graph remove --node http://localhost:8020/ brokenomics/new-order-avalanche", + "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 brokenomics/new-order-avalanche" + }, + "dependencies": { + "@graphprotocol/graph-cli": "0.26.0", + "@graphprotocol/graph-ts": "0.24.1" + } +} diff --git a/schema.graphql b/schema.graphql new file mode 100644 index 0000000..b647495 --- /dev/null +++ b/schema.graphql @@ -0,0 +1,6 @@ +type ExampleEntity @entity { + id: ID! + count: BigInt! + owner: Bytes! # address + spender: Bytes! # address +} diff --git a/src/mapping.ts b/src/mapping.ts new file mode 100644 index 0000000..5286e39 --- /dev/null +++ b/src/mapping.ts @@ -0,0 +1,78 @@ +import { BigInt } from "@graphprotocol/graph-ts" +import { + NewOrder, + Approval, + RoleAdminChanged, + RoleGranted, + RoleRevoked, + Transfer +} from "../generated/NewOrder/NewOrder" +import { ExampleEntity } from "../generated/schema" + +export function handleApproval(event: Approval): 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.owner = event.params.owner + entity.spender = event.params.spender + + // 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.DEFAULT_ADMIN_ROLE(...) + // - contract.DOMAIN_SEPARATOR(...) + // - contract.MINTER_ROLE(...) + // - contract.allowance(...) + // - contract.approve(...) + // - contract.balanceOf(...) + // - contract.decimals(...) + // - contract.decreaseAllowance(...) + // - contract.getRoleAdmin(...) + // - contract.getRoleMember(...) + // - contract.getRoleMemberCount(...) + // - contract.hasRole(...) + // - contract.increaseAllowance(...) + // - contract.name(...) + // - contract.nonces(...) + // - contract.symbol(...) + // - contract.totalSupply(...) + // - contract.transfer(...) + // - contract.transferFrom(...) +} + +export function handleRoleAdminChanged(event: RoleAdminChanged): void {} + +export function handleRoleGranted(event: RoleGranted): void {} + +export function handleRoleRevoked(event: RoleRevoked): void {} + +export function handleTransfer(event: Transfer): void {} diff --git a/subgraph.yaml b/subgraph.yaml new file mode 100644 index 0000000..c282ebd --- /dev/null +++ b/subgraph.yaml @@ -0,0 +1,35 @@ +specVersion: 0.0.1 +schema: + file: ./schema.graphql +dataSources: + - kind: ethereum + name: NewOrder + network: avalanche + source: + address: "0x4Bfc90322dD638F81F034517359BD447f8E0235a" + abi: NewOrder + mapping: + kind: ethereum/events + apiVersion: 0.0.5 + language: wasm/assemblyscript + entities: + - Approval + - RoleAdminChanged + - RoleGranted + - RoleRevoked + - Transfer + abis: + - name: NewOrder + file: ./abis/NewOrder.json + eventHandlers: + - event: Approval(indexed address,indexed address,uint256) + handler: handleApproval + - event: RoleAdminChanged(indexed bytes32,indexed bytes32,indexed bytes32) + handler: handleRoleAdminChanged + - event: RoleGranted(indexed bytes32,indexed address,indexed address) + handler: handleRoleGranted + - event: RoleRevoked(indexed bytes32,indexed address,indexed address) + handler: handleRoleRevoked + - event: Transfer(indexed address,indexed address,uint256) + handler: handleTransfer + file: ./src/mapping.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"] +}