diff --git a/packages/subgraph-mainchain/.env b/packages/subgraph-mainchain/.env new file mode 100644 index 00000000..132528ba --- /dev/null +++ b/packages/subgraph-mainchain/.env @@ -0,0 +1,4 @@ +NETWORK_NAME=mainchain +GRAPH_KEY=DENET_KEY +SUBGRAPH_NAME=bosagora/dms-osx +SUBGRAPH_VERSION=v0.0.1 diff --git a/packages/subgraph-mainchain/.env.mainchain b/packages/subgraph-mainchain/.env.mainchain new file mode 100644 index 00000000..132528ba --- /dev/null +++ b/packages/subgraph-mainchain/.env.mainchain @@ -0,0 +1,4 @@ +NETWORK_NAME=mainchain +GRAPH_KEY=DENET_KEY +SUBGRAPH_NAME=bosagora/dms-osx +SUBGRAPH_VERSION=v0.0.1 diff --git a/packages/subgraph-mainchain/.gitignore b/packages/subgraph-mainchain/.gitignore new file mode 100644 index 00000000..3155d04c --- /dev/null +++ b/packages/subgraph-mainchain/.gitignore @@ -0,0 +1,3 @@ +subgraph.yaml +generated/ +build/ diff --git a/packages/subgraph-mainchain/LICENSE b/packages/subgraph-mainchain/LICENSE new file mode 100644 index 00000000..f8317ffa --- /dev/null +++ b/packages/subgraph-mainchain/LICENSE @@ -0,0 +1,14 @@ +Copyright (c) 2023 BOSAGORA Foundation + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . diff --git a/packages/subgraph-mainchain/manifest/data/mainchain.json b/packages/subgraph-mainchain/manifest/data/mainchain.json new file mode 100644 index 00000000..15423841 --- /dev/null +++ b/packages/subgraph-mainchain/manifest/data/mainchain.json @@ -0,0 +1,21 @@ +{ + "info": "# Do not edit subgraph.yaml,this is a generated file. \n# Instead, edit subgraph.placeholder.yaml and run: yarn manifest", + "network": "mainchain", + "dataSources": { + "LoyaltyToken": { + "name": "LoyaltyToken", + "address": "0xB1A90a5C6e30d64Ab6f64C30eD392F46eDBcb022", + "startBlock": 1 + }, + "ChainBridge": { + "name": "ChainBridge", + "address": "0x979a62090BDCff36F2e140F6915fbAdA7510cb6a", + "startBlock": 1 + }, + "LoyaltyBridge": { + "name": "LoyaltyBridge", + "address": "0x4Ca91738C7cD24895467c6d550D96BE8dC4b33AA", + "startBlock": 1 + } + } +} diff --git a/packages/subgraph-mainchain/manifest/subgraph.placeholder.yaml b/packages/subgraph-mainchain/manifest/subgraph.placeholder.yaml new file mode 100644 index 00000000..1fdabe8f --- /dev/null +++ b/packages/subgraph-mainchain/manifest/subgraph.placeholder.yaml @@ -0,0 +1,74 @@ +specVersion: 0.0.5 +description: A template for Sub Graphs +repository: https://github.com/bosagora/dms-osx +schema: + file: ./schema.graphql +dataSources: + - kind: ethereum + name: {{dataSources.LoyaltyToken.name}} + network: {{network}} + source: + address: '{{dataSources.LoyaltyToken.address}}' + abi: LoyaltyToken + startBlock: {{dataSources.LoyaltyToken.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - Transfer + abis: + - name: LoyaltyToken + file: $DMS_OSX_MODULE/artifacts/loyalty-tokens/contracts/LoyaltyToken.sol/LoyaltyToken.json + eventHandlers: + - event: Transfer(indexed address,indexed address,uint256) + handler: handleTransfer + file: ./src/loyalty-token.ts + + - kind: ethereum + name: {{dataSources.ChainBridge.name}} + network: {{network}} + source: + address: '{{dataSources.ChainBridge.address}}' + abi: ChainBridge + startBlock: {{dataSources.ChainBridge.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - BridgeDeposited + - BridgeWithdrawn + abis: + - name: ChainBridge + file: $DMS_OSX_MODULE/artifacts/dms-bridge-contracts/contracts/bridge/Bridge.sol/Bridge.json + eventHandlers: + - event: BridgeDeposited(bytes32,bytes32,address,uint256,uint256) + handler: handleBridgeDeposited + - event: BridgeWithdrawn(bytes32,bytes32,address,uint256,uint256) + handler: handleBridgeWithdrawn + file: ./src/chain-bridge.ts + + - kind: ethereum + name: {{dataSources.LoyaltyBridge.name}} + network: {{network}} + source: + address: '{{dataSources.LoyaltyBridge.address}}' + abi: LoyaltyBridge + startBlock: {{dataSources.LoyaltyBridge.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - BridgeDeposited + - BridgeWithdrawn + abis: + - name: LoyaltyBridge + file: $DMS_OSX_MODULE/artifacts/dms-bridge-contracts/contracts/bridge/Bridge.sol/Bridge.json + eventHandlers: + - event: BridgeDeposited(bytes32,bytes32,address,uint256,uint256) + handler: handleBridgeDeposited + - event: BridgeWithdrawn(bytes32,bytes32,address,uint256,uint256) + handler: handleBridgeWithdrawn + file: ./src/loyalty-bridge.ts diff --git a/packages/subgraph-mainchain/package.json b/packages/subgraph-mainchain/package.json new file mode 100644 index 00000000..b5f93f1d --- /dev/null +++ b/packages/subgraph-mainchain/package.json @@ -0,0 +1,29 @@ +{ + "name": "dms-osx-subgraph-mainchain", + "version": "1.0.0", + "description": "The DMS Subgraph for mainchain", + "homepage": "https://github.com/bosagora/dms-osx", + "author": "BOSagora Foundation", + "license": "AGPL-3.0-or-later", + "scripts": { + "build:contracts": "cd ../contracts && yarn build", + "manifest": "scripts/build-manifest.sh", + "build": "scripts/build-subgraph.sh", + "deploy": "scripts/deploy-subgraph.sh", + "create:mainchain": "graph create bosagora/dms-osx-mainchain --node http://localhost:8020", + "remove:mainchain": "graph remove bosagora/dms-osx-mainchain --node http://localhost:8020", + "deploy:mainchain": "LOCAL=true scripts/deploy-subgraph.sh", + "formatting:check": "prettier '**/*.{json,ts,js}' -c", + "formatting:write": "prettier '**/*.{json,ts,js}' --write" + }, + "devDependencies": { + "@graphprotocol/graph-cli": "^0.55.0", + "@graphprotocol/graph-ts": "^0.31.0", + "matchstick-as": "^0.5.1", + "mustache": "^4.2.0", + "prettier": "^2.5.1", + "prettier-plugin-solidity": "^1.1.1", + "tslint": "^6.1.3", + "tslint-config-prettier": "^1.18.0" + } +} diff --git a/packages/subgraph-mainchain/schema.graphql b/packages/subgraph-mainchain/schema.graphql new file mode 100644 index 00000000..3df817ab --- /dev/null +++ b/packages/subgraph-mainchain/schema.graphql @@ -0,0 +1,57 @@ +type LoyaltyTransfer @entity(immutable: true) { + id: Bytes! + from: Bytes! # address + to: Bytes! # address + value: BigInt! # uint256 + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +type ChainBridgeDeposited @entity(immutable: true) { + id: Bytes! + tokenId: Bytes! # bytes32 + depositId: Bytes! # bytes32 + account: Bytes! # address + amount: BigInt! # uint256 + balance: BigInt! # uint256 + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +type ChainBridgeWithdrawn @entity(immutable: true) { + id: Bytes! + tokenId: Bytes! # bytes32 + withdrawId: Bytes! # bytes32 + account: Bytes! # address + amount: BigInt! # uint256 + balance: BigInt! # uint256 + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +type LoyaltyBridgeDeposited @entity(immutable: true) { + id: Bytes! + tokenId: Bytes! # bytes32 + depositId: Bytes! # bytes32 + account: Bytes! # address + amount: BigInt! # uint256 + balance: BigInt! # uint256 + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +type LoyaltyBridgeWithdrawn @entity(immutable: true) { + id: Bytes! + tokenId: Bytes! # bytes32 + withdrawId: Bytes! # bytes32 + account: Bytes! # address + amount: BigInt! # uint256 + balance: BigInt! # uint256 + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} diff --git a/packages/subgraph-mainchain/scripts/build-manifest.sh b/packages/subgraph-mainchain/scripts/build-manifest.sh new file mode 100755 index 00000000..f93960c0 --- /dev/null +++ b/packages/subgraph-mainchain/scripts/build-manifest.sh @@ -0,0 +1,29 @@ +#!/bin/bash + + +if [ -f .env ] +then + export $(cat .env | sed 's/#.*//g' | xargs) +fi + +if [ -z "$NETWORK_NAME" ] +then + echo "env is not set, exiting..." + exit -1 +else + echo "env Network is set to: $NETWORK_NAME" +fi + +FILE=$NETWORK_NAME'.json' +DATA=manifest/data/$FILE + +DMS_OSX_MODULE=$(node -e 'console.log(require("path").dirname(require.resolve("dms-osx-artifacts/package.json")))') + +echo 'Generating manifest from data file: '$DATA +cat $DATA + +mustache \ + $DATA \ + manifest/subgraph.placeholder.yaml \ + | sed -e "s#\$DMS_OSX_MODULE#$DMS_OSX_MODULE#g" \ + > subgraph.yaml diff --git a/packages/subgraph-mainchain/scripts/build-subgraph.sh b/packages/subgraph-mainchain/scripts/build-subgraph.sh new file mode 100755 index 00000000..3f67c211 --- /dev/null +++ b/packages/subgraph-mainchain/scripts/build-subgraph.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -eu + +if [ ! -f "./subgraph.yaml" ]; then + echo "The file subgraph.yaml doesn’t exist. Did you run: yarn manifest?" + exit 1 +fi + +rm -rf generated +rm -rf build + +graph codegen +graph build diff --git a/packages/subgraph-mainchain/scripts/deploy-subgraph.sh b/packages/subgraph-mainchain/scripts/deploy-subgraph.sh new file mode 100755 index 00000000..dc0a64e9 --- /dev/null +++ b/packages/subgraph-mainchain/scripts/deploy-subgraph.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +if [ -f .env ] +then + export $(cat .env | sed 's/#.*//g' | xargs) +fi + +if [ -z "$NETWORK_NAME" ] || [ -z "$SUBGRAPH_NAME" ] || [ -z "$GRAPH_KEY" ] || [ -z "$SUBGRAPH_VERSION" ] +then + echo "env variables are not set properly, exiting..." + exit -1 +fi + +# Exit script as soon as a command fails. +set -o errexit + +# Build manifest +echo '' +echo '> Building manifest file subgraph.yaml' +./scripts/build-manifest.sh + +# Generate types +echo '' +echo '> Generating types' +graph codegen + +# Prepare subgraph name +FULLNAME=$SUBGRAPH_NAME-$NETWORK_NAME +if [ "$STAGING" ]; then + FULLNAME=$FULLNAME-staging +fi + +echo '' +echo '> Deploying subgraph: '$FULLNAME + +# Deploy subgraph +if [ "$LOCAL" ] +then + graph deploy $FULLNAME \ + --ipfs http://localhost:5001 \ + --node http://localhost:8020 +else + NODE_URL='https://subgraph-deploy-mainnet.dao.bosagora.org' + graph deploy $FULLNAME \ + --version-label $SUBGRAPH_VERSION \ + --node $NODE_URL \ + --deploy-key $GRAPH_KEY > deploy-output.txt + + SUBGRAPH_ID=$(grep "Build completed:" deploy-output.txt | grep -oE "Qm[a-zA-Z0-9]{44}") + rm deploy-output.txt + echo "The Graph deployment complete: ${SUBGRAPH_ID}" +fi diff --git a/packages/subgraph-mainchain/src/chain-bridge.ts b/packages/subgraph-mainchain/src/chain-bridge.ts new file mode 100644 index 00000000..d3051f11 --- /dev/null +++ b/packages/subgraph-mainchain/src/chain-bridge.ts @@ -0,0 +1,36 @@ +import { + BridgeDeposited as BridgeDepositedEvent, + BridgeWithdrawn as BridgeWithdrawnEvent, +} from "../generated/ChainBridge/ChainBridge"; +import { ChainBridgeDeposited, ChainBridgeWithdrawn } from "../generated/schema"; +import { AmountUnit } from "dms-osx-subgraph-sidechain/src/utils"; + +export function handleBridgeDeposited(event: BridgeDepositedEvent): void { + let entity = new ChainBridgeDeposited(event.transaction.hash.concatI32(event.logIndex.toI32())); + entity.tokenId = event.params.tokenId; + entity.depositId = event.params.depositId; + entity.account = event.params.account; + entity.amount = event.params.amount.div(AmountUnit); + entity.balance = event.params.balance.div(AmountUnit); + + entity.blockNumber = event.block.number; + entity.blockTimestamp = event.block.timestamp; + entity.transactionHash = event.transaction.hash; + + entity.save(); +} + +export function handleBridgeWithdrawn(event: BridgeWithdrawnEvent): void { + let entity = new ChainBridgeWithdrawn(event.transaction.hash.concatI32(event.logIndex.toI32())); + entity.tokenId = event.params.tokenId; + entity.withdrawId = event.params.withdrawId; + entity.account = event.params.account; + entity.amount = event.params.amount.div(AmountUnit); + entity.balance = event.params.balance.div(AmountUnit); + + entity.blockNumber = event.block.number; + entity.blockTimestamp = event.block.timestamp; + entity.transactionHash = event.transaction.hash; + + entity.save(); +} diff --git a/packages/subgraph-mainchain/src/loyalty-bridge.ts b/packages/subgraph-mainchain/src/loyalty-bridge.ts new file mode 100644 index 00000000..5faf35cb --- /dev/null +++ b/packages/subgraph-mainchain/src/loyalty-bridge.ts @@ -0,0 +1,36 @@ +import { + BridgeDeposited as BridgeDepositedEvent, + BridgeWithdrawn as BridgeWithdrawnEvent, +} from "../generated/LoyaltyBridge/LoyaltyBridge"; +import { LoyaltyBridgeDeposited, LoyaltyBridgeWithdrawn } from "../generated/schema"; +import { AmountUnit } from "dms-osx-subgraph-sidechain/src/utils"; + +export function handleBridgeDeposited(event: BridgeDepositedEvent): void { + let entity = new LoyaltyBridgeDeposited(event.transaction.hash.concatI32(event.logIndex.toI32())); + entity.tokenId = event.params.tokenId; + entity.depositId = event.params.depositId; + entity.account = event.params.account; + entity.amount = event.params.amount.div(AmountUnit); + entity.balance = event.params.balance.div(AmountUnit); + + entity.blockNumber = event.block.number; + entity.blockTimestamp = event.block.timestamp; + entity.transactionHash = event.transaction.hash; + + entity.save(); +} + +export function handleBridgeWithdrawn(event: BridgeWithdrawnEvent): void { + let entity = new LoyaltyBridgeWithdrawn(event.transaction.hash.concatI32(event.logIndex.toI32())); + entity.tokenId = event.params.tokenId; + entity.withdrawId = event.params.withdrawId; + entity.account = event.params.account; + entity.amount = event.params.amount.div(AmountUnit); + entity.balance = event.params.balance.div(AmountUnit); + + entity.blockNumber = event.block.number; + entity.blockTimestamp = event.block.timestamp; + entity.transactionHash = event.transaction.hash; + + entity.save(); +} diff --git a/packages/subgraph-mainchain/src/loyalty-token.ts b/packages/subgraph-mainchain/src/loyalty-token.ts new file mode 100644 index 00000000..c0846cde --- /dev/null +++ b/packages/subgraph-mainchain/src/loyalty-token.ts @@ -0,0 +1,16 @@ +import { Transfer as TransferEvent } from "../generated/LoyaltyToken/LoyaltyToken"; +import { LoyaltyTransfer } from "../generated/schema"; +import { AmountUnit } from "./utils"; + +export function handleTransfer(event: TransferEvent): void { + let entity = new LoyaltyTransfer(event.transaction.hash.concatI32(event.logIndex.toI32())); + entity.from = event.params.from; + entity.to = event.params.to; + entity.value = event.params.value.div(AmountUnit); + + entity.blockNumber = event.block.number; + entity.blockTimestamp = event.block.timestamp; + entity.transactionHash = event.transaction.hash; + + entity.save(); +} diff --git a/packages/subgraph-mainchain/src/utils.ts b/packages/subgraph-mainchain/src/utils.ts new file mode 100644 index 00000000..44a9c7bd --- /dev/null +++ b/packages/subgraph-mainchain/src/utils.ts @@ -0,0 +1,7 @@ +import { BigInt, Bytes } from "@graphprotocol/graph-ts"; + +export const AmountUnit = BigInt.fromI32(1_000_000_000); +export const NullAccount: Bytes = Bytes.fromHexString("0x0000000000000000000000000000000000000000"); +export const NullBytes32: Bytes = Bytes.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000" +); diff --git a/packages/subgraph-mainchain/tsconfig.json b/packages/subgraph-mainchain/tsconfig.json new file mode 100644 index 00000000..2a5424fc --- /dev/null +++ b/packages/subgraph-mainchain/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", + "include": ["src", "tests"] +} diff --git a/packages/subgraph-sidechain/manifest/data/sidechain.json b/packages/subgraph-sidechain/manifest/data/sidechain.json index 6577226f..a083b026 100644 --- a/packages/subgraph-sidechain/manifest/data/sidechain.json +++ b/packages/subgraph-sidechain/manifest/data/sidechain.json @@ -41,6 +41,16 @@ "name": "Shop", "address": "0xB4B0d4D6aAd2f963CC2FaeCBb4B8C94C3eeE6DB8", "startBlock": 1 + }, + "LoyaltyToken": { + "name": "LoyaltyToken", + "address": "0xB1A90a5C6e30d64Ab6f64C30eD392F46eDBcb022", + "startBlock": 1 + }, + "ChainBridge": { + "name": "ChainBridge", + "address": "0x02aAcAC866385A86ddA9a3C1FB7923c4A0433B31", + "startBlock": 1 } } } diff --git a/packages/subgraph-sidechain/manifest/subgraph.placeholder.yaml b/packages/subgraph-sidechain/manifest/subgraph.placeholder.yaml index c805eca9..3b4a8333 100644 --- a/packages/subgraph-sidechain/manifest/subgraph.placeholder.yaml +++ b/packages/subgraph-sidechain/manifest/subgraph.placeholder.yaml @@ -1,5 +1,5 @@ specVersion: 0.0.5 -description: A template for Aragon subgraphs +description: A template for Sub Graphs repository: https://github.com/bosagora/dms-osx schema: file: ./schema.graphql @@ -219,3 +219,48 @@ dataSources: - event: UpdatedShop(bytes32,string,string,address,uint8) handler: handleUpdatedShop file: ./src/shop.ts + + - kind: ethereum + name: {{dataSources.LoyaltyToken.name}} + network: {{network}} + source: + address: '{{dataSources.LoyaltyToken.address}}' + abi: LoyaltyToken + startBlock: {{dataSources.LoyaltyToken.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - Transfer + abis: + - name: LoyaltyToken + file: $DMS_OSX_MODULE/artifacts/loyalty-tokens/contracts/LoyaltyToken.sol/LoyaltyToken.json + eventHandlers: + - event: Transfer(indexed address,indexed address,uint256) + handler: handleTransfer + file: ./src/loyalty-token.ts + + - kind: ethereum + name: {{dataSources.ChainBridge.name}} + network: {{network}} + source: + address: '{{dataSources.ChainBridge.address}}' + abi: ChainBridge + startBlock: {{dataSources.ChainBridge.startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - BridgeDeposited + - BridgeWithdrawn + abis: + - name: ChainBridge + file: $DMS_OSX_MODULE/artifacts/dms-bridge-contracts/contracts/bridge/Bridge.sol/Bridge.json + eventHandlers: + - event: BridgeDeposited(bytes32,bytes32,address,uint256,uint256) + handler: handleBridgeDeposited + - event: BridgeWithdrawn(bytes32,bytes32,address,uint256,uint256) + handler: handleBridgeWithdrawn + file: ./src/chain-bridge.ts diff --git a/packages/subgraph-sidechain/package.json b/packages/subgraph-sidechain/package.json index 45889ee0..b7f31ea6 100644 --- a/packages/subgraph-sidechain/package.json +++ b/packages/subgraph-sidechain/package.json @@ -1,7 +1,7 @@ { "name": "dms-osx-subgraph-sidechain", "version": "1.0.0", - "description": "The DMS OSx Subgraph", + "description": "The DMS Subgraph for sidechain", "homepage": "https://github.com/bosagora/dms-osx", "author": "BOSagora Foundation", "license": "AGPL-3.0-or-later", diff --git a/packages/subgraph-sidechain/schema.graphql b/packages/subgraph-sidechain/schema.graphql index eea622a0..d36c037f 100644 --- a/packages/subgraph-sidechain/schema.graphql +++ b/packages/subgraph-sidechain/schema.graphql @@ -158,7 +158,7 @@ type BurnedUnPayablePoint @entity(immutable: true) { transactionHash: Bytes! } -type BridgeDeposited @entity(immutable: true) { +type LoyaltyBridgeDeposited @entity(immutable: true) { id: Bytes! tokenId: Bytes! # bytes32 depositId: Bytes! # bytes32 @@ -170,7 +170,41 @@ type BridgeDeposited @entity(immutable: true) { transactionHash: Bytes! } -type BridgeWithdrawn @entity(immutable: true) { +type LoyaltyBridgeWithdrawn @entity(immutable: true) { + id: Bytes! + tokenId: Bytes! # bytes32 + withdrawId: Bytes! # bytes32 + account: Bytes! # address + amount: BigInt! # uint256 + balance: BigInt! # uint256 + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +type LoyaltyTransfer @entity(immutable: true) { + id: Bytes! + from: Bytes! # address + to: Bytes! # address + value: BigInt! # uint256 + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +type ChainBridgeDeposited @entity(immutable: true) { + id: Bytes! + tokenId: Bytes! # bytes32 + depositId: Bytes! # bytes32 + account: Bytes! # address + amount: BigInt! # uint256 + balance: BigInt! # uint256 + blockNumber: BigInt! + blockTimestamp: BigInt! + transactionHash: Bytes! +} + +type ChainBridgeWithdrawn @entity(immutable: true) { id: Bytes! tokenId: Bytes! # bytes32 withdrawId: Bytes! # bytes32 diff --git a/packages/subgraph-sidechain/scripts/deploy-subgraph.sh b/packages/subgraph-sidechain/scripts/deploy-subgraph.sh index 9580139c..dc0a64e9 100755 --- a/packages/subgraph-sidechain/scripts/deploy-subgraph.sh +++ b/packages/subgraph-sidechain/scripts/deploy-subgraph.sh @@ -40,16 +40,7 @@ then --ipfs http://localhost:5001 \ --node http://localhost:8020 else - NODE_URL='https://app.satsuma.xyz/api/subgraphs/deploy' - - if [ "$NETWORK_NAME" == 'bosagora' ] - then - NODE_URL='https://subgraph-deploy-mainnet.dao.bosagora.org' - elif [ "$NETWORK_NAME" == 'athens' ] - then - NODE_URL='https://subgraph-deploy-athens.dao.bosagora.org' - fi - + NODE_URL='https://subgraph-deploy-mainnet.dao.bosagora.org' graph deploy $FULLNAME \ --version-label $SUBGRAPH_VERSION \ --node $NODE_URL \ diff --git a/packages/subgraph-sidechain/src/chain-bridge.ts b/packages/subgraph-sidechain/src/chain-bridge.ts new file mode 100644 index 00000000..3ba3e0d6 --- /dev/null +++ b/packages/subgraph-sidechain/src/chain-bridge.ts @@ -0,0 +1,36 @@ +import { + BridgeDeposited as BridgeDepositedEvent, + BridgeWithdrawn as BridgeWithdrawnEvent, +} from "../generated/ChainBridge/ChainBridge"; +import { ChainBridgeDeposited, ChainBridgeWithdrawn } from "../generated/schema"; +import { AmountUnit } from "./utils"; + +export function handleBridgeDeposited(event: BridgeDepositedEvent): void { + let entity = new ChainBridgeDeposited(event.transaction.hash.concatI32(event.logIndex.toI32())); + entity.tokenId = event.params.tokenId; + entity.depositId = event.params.depositId; + entity.account = event.params.account; + entity.amount = event.params.amount.div(AmountUnit); + entity.balance = event.params.balance.div(AmountUnit); + + entity.blockNumber = event.block.number; + entity.blockTimestamp = event.block.timestamp; + entity.transactionHash = event.transaction.hash; + + entity.save(); +} + +export function handleBridgeWithdrawn(event: BridgeWithdrawnEvent): void { + let entity = new ChainBridgeWithdrawn(event.transaction.hash.concatI32(event.logIndex.toI32())); + entity.tokenId = event.params.tokenId; + entity.withdrawId = event.params.withdrawId; + entity.account = event.params.account; + entity.amount = event.params.amount.div(AmountUnit); + entity.balance = event.params.balance.div(AmountUnit); + + entity.blockNumber = event.block.number; + entity.blockTimestamp = event.block.timestamp; + entity.transactionHash = event.transaction.hash; + + entity.save(); +} diff --git a/packages/subgraph-sidechain/src/ledger.ts b/packages/subgraph-sidechain/src/ledger.ts index 8c45d379..4003cfcb 100644 --- a/packages/subgraph-sidechain/src/ledger.ts +++ b/packages/subgraph-sidechain/src/ledger.ts @@ -31,8 +31,8 @@ import { UserTradeHistory, UserUnPayableTradeHistory, LoyaltyPaymentEvent, - BridgeDeposited, - BridgeWithdrawn, + LoyaltyBridgeDeposited, + LoyaltyBridgeWithdrawn, BurnedPoint, BurnedUnPayablePoint, } from "../generated/schema"; @@ -832,12 +832,12 @@ export function handleBurnedUnPayablePointForHistory(event: BurnedUnPayablePoint // region LoyaltyBridge export function handleBridgeDeposited(event: BridgeDepositedEvent): void { - let entity = new BridgeDeposited(event.transaction.hash.concatI32(event.logIndex.toI32())); + let entity = new LoyaltyBridgeDeposited(event.transaction.hash.concatI32(event.logIndex.toI32())); entity.tokenId = event.params.tokenId; entity.depositId = event.params.depositId; entity.account = event.params.account; - entity.amount = event.params.amount; - entity.balance = event.params.balance; + entity.amount = event.params.amount.div(AmountUnit); + entity.balance = event.params.balance.div(AmountUnit); entity.blockNumber = event.block.number; entity.blockTimestamp = event.block.timestamp; @@ -882,12 +882,12 @@ export function handleBridgeDepositedForHistory(event: BridgeDepositedEvent): vo } export function handleBridgeWithdrawn(event: BridgeWithdrawnEvent): void { - let entity = new BridgeWithdrawn(event.transaction.hash.concatI32(event.logIndex.toI32())); + let entity = new LoyaltyBridgeWithdrawn(event.transaction.hash.concatI32(event.logIndex.toI32())); entity.tokenId = event.params.tokenId; entity.withdrawId = event.params.withdrawId; entity.account = event.params.account; - entity.amount = event.params.amount; - entity.balance = event.params.balance; + entity.amount = event.params.amount.div(AmountUnit); + entity.balance = event.params.balance.div(AmountUnit); entity.blockNumber = event.block.number; entity.blockTimestamp = event.block.timestamp; diff --git a/packages/subgraph-sidechain/src/loyalty-token.ts b/packages/subgraph-sidechain/src/loyalty-token.ts new file mode 100644 index 00000000..c0846cde --- /dev/null +++ b/packages/subgraph-sidechain/src/loyalty-token.ts @@ -0,0 +1,16 @@ +import { Transfer as TransferEvent } from "../generated/LoyaltyToken/LoyaltyToken"; +import { LoyaltyTransfer } from "../generated/schema"; +import { AmountUnit } from "./utils"; + +export function handleTransfer(event: TransferEvent): void { + let entity = new LoyaltyTransfer(event.transaction.hash.concatI32(event.logIndex.toI32())); + entity.from = event.params.from; + entity.to = event.params.to; + entity.value = event.params.value.div(AmountUnit); + + entity.blockNumber = event.block.number; + entity.blockTimestamp = event.block.timestamp; + entity.transactionHash = event.transaction.hash; + + entity.save(); +}