Skip to content

Commit

Permalink
feat(subgraph): update voting, finance, and tokens connectors to late…
Browse files Browse the repository at this point in the history
…st graph version
  • Loading branch information
0xGabi committed Nov 25, 2023
1 parent 68c5526 commit 577f62e
Show file tree
Hide file tree
Showing 40 changed files with 6,866 additions and 4,440 deletions.
45 changes: 45 additions & 0 deletions packages/connect-finance/subgraph/manifest/data/optimism.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"network": "optimism",
"dataSources": {
"Organizations": [],
"OrganizationFactories": [
{
"name": "[email protected]",
"address": "0x0a42106615233D0E6F9811d0cBb7ddC83170Fe5E",
"startBlock": "107569173"
}
],
"OrganizationTemplates": [
{
"name": "[email protected]",
"address": "0x47fe46411B9Ec36a0339f2Efb002AD56b1F9D37f",
"startBlock": 107695574
},
{
"name": "[email protected]",
"address": "0xE692b0e7e04a0D3D81F1a11e2b3B1e06271ca3cC",
"startBlock": 107695698
},
{
"name": "[email protected]",
"address": "0x138E5FE852D2cCf40310919Fdc6261B884C9e557",
"startBlock": 107695888
},
{
"name": "[email protected]",
"address": "0xc35f77BD8e1fF947Ba3ab120Aa35f704d6B63157",
"startBlock": 107696029
},
{
"name": "[email protected]",
"address": "0xe3B3304b94D2160AF5547716F322d35Ae72B6224",
"startBlock": 107696149
}
],
"LegacyOrganizationTemplates": [],
"TokenFactories": [],
"Tokens": []
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
startBlock: {{startBlock}}
mapping:
kind: ethereum/events
apiVersion: 0.0.1
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- NoEnt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
startBlock: {{startBlock}}
mapping:
kind: ethereum/events
apiVersion: 0.0.1
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- NoEnt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
startBlock: {{startBlock}}
mapping:
kind: ethereum/events
apiVersion: 0.0.1
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- NoEnt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{/startBlock}}
mapping:
kind: ethereum/events
apiVersion: 0.0.1
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- NoEnt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{/startBlock}}
mapping:
kind: ethereum/events
apiVersion: 0.0.1
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- NoEnt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
startBlock: {{startBlock}}
mapping:
kind: ethereum/events
apiVersion: 0.0.1
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- NoEnt
Expand Down
12 changes: 5 additions & 7 deletions packages/connect-finance/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
"build": "rm -rf build; graph build",
"manifest-mainnet": "scripts/build-manifest.sh mainnet",
"manifest-mainnet-staging": "env STAGING=true scripts/build-manifest.sh mainnet",
"manifest-rinkeby": "scripts/build-manifest.sh rinkeby",
"manifest-rinkeby-staging": "env STAGING=true scripts/build-manifest.sh rinkeby",
"manifest-xdai": "scripts/build-manifest.sh xdai",
"manifest-optimism": "scripts/build-manifest.sh optimism",
"deploy-mainnet": "scripts/deploy.sh aragon finance mainnet",
"deploy-mainnet-staging": "env STAGING=true scripts/deploy.sh aragon finance mainnet",
"deploy-rinkeby": "scripts/deploy.sh aragon finance rinkeby",
"deploy-rinkeby-staging": "env STAGING=true scripts/deploy.sh aragon finance rinkeby",
"deploy-xdai": "scripts/deploy.sh aragon finance xdai"
"deploy-xdai": "scripts/deploy.sh aragon finance xdai",
"deploy-optimism": "scripts/deploy.sh blossomlabs finance optimism"
},
"devDependencies": {
"@graphprotocol/graph-cli": "^0.19.0",
"@graphprotocol/graph-ts": "^0.19.0",
"@graphprotocol/graph-cli": "^0.54.0",
"@graphprotocol/graph-ts": "^0.31.0",
"mustache": "^4.0.1"
},
"dependencies": {
Expand Down
29 changes: 15 additions & 14 deletions packages/connect-finance/subgraph/src/Finance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Address, BigInt } from '@graphprotocol/graph-ts'
/* eslint-disable @typescript-eslint/no-use-before-define */
import { Address, BigInt, Bytes } from '@graphprotocol/graph-ts'
import {
NewTransaction as NewTransactionEvent,
Finance as FinanceContract,
Expand All @@ -9,7 +10,7 @@ import {
} from '../generated/schema'

export function handleNewTransaction(event: NewTransactionEvent): void {
let transaction = _getTransactionEntity(
const transaction = _getTransactionEntity(
event.address,
event.params.transactionId
)
Expand All @@ -23,9 +24,9 @@ export function handleNewTransaction(event: NewTransactionEvent): void {

transaction.save()

let tokenBalance = _getTokenBalanceEntity(
const tokenBalance = _getTokenBalanceEntity(
event.address,
transaction.token as Address
transaction.token
)

_updateTokenBalance(tokenBalance, transaction)
Expand All @@ -37,19 +38,19 @@ function _getTransactionEntity(
appAddress: Address,
transactionId: BigInt
): TransactionEntity {
let transactionEntityId = _getTransactionEntityId(appAddress, transactionId)
const transactionEntityId = _getTransactionEntityId(appAddress, transactionId)

let transaction = TransactionEntity.load(transactionEntityId)
if (!transaction) {
transaction = new TransactionEntity(transactionEntityId)

let finance = FinanceContract.bind(appAddress)
const finance = FinanceContract.bind(appAddress)

transaction.orgAddress = finance.kernel()
transaction.appAddress = appAddress
}

return transaction!
return transaction
}

function _getTransactionEntityId(
Expand All @@ -66,26 +67,26 @@ function _getTransactionEntityId(

function _getTokenBalanceEntity(
appAddress: Address,
token: Address
token: Bytes
): TokenBalanceEntity {
let tokenBalanceEntityId = _getTokenBalanceId(appAddress, token)
const tokenBalanceEntityId = _getTokenBalanceId(appAddress, token)

let tokenBalance = TokenBalanceEntity.load(tokenBalanceEntityId)
if (!tokenBalance) {
tokenBalance = new TokenBalanceEntity(tokenBalanceEntityId)

let finance = FinanceContract.bind(appAddress)
const finance = FinanceContract.bind(appAddress)

tokenBalance.token = token
tokenBalance.balance = BigInt.fromI32(0)
tokenBalance.orgAddress = finance.kernel()
tokenBalance.appAddress = appAddress
}

return tokenBalance!
return tokenBalance
}

function _getTokenBalanceId(appAddress: Address, token: Address): string {
function _getTokenBalanceId(appAddress: Address, token: Bytes): string {
return (
'appAddress:' +
appAddress.toHexString() +
Expand All @@ -99,9 +100,9 @@ function _populateTransactionDataFromContract(
appAddress: Address,
transactionId: BigInt
): void {
let finance = FinanceContract.bind(appAddress)
const finance = FinanceContract.bind(appAddress)

let transactionData = finance.getTransaction(transactionId)
const transactionData = finance.getTransaction(transactionId)

transaction.token = transactionData.value4
transaction.date = transactionData.value7
Expand Down
65 changes: 35 additions & 30 deletions packages/connect-finance/subgraph/src/aragon/aragon.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Address, DataSourceTemplate } from '@graphprotocol/graph-ts'
/* eslint-disable @typescript-eslint/no-use-before-define */
import { Address, Bytes, DataSourceTemplate } from '@graphprotocol/graph-ts'
import { AragonInfo as AragonInfoEntity } from '../../generated/schema'
import { Kernel as KernelTemplate } from '../../generated/templates'
import { MiniMeToken as MiniMeTokenTemplate } from '../../generated/templates'
import * as hooks from '../aragon-hooks'


export function processOrg(orgAddress: Address): void {
if (!_isRegistered(orgAddress, 'org')) {
KernelTemplate.create(orgAddress)
Expand All @@ -15,7 +17,7 @@ export function processOrg(orgAddress: Address): void {

export function processApp(appAddress: Address, appId: string): void {
if (!_isRegistered(appAddress, 'app')) {
let templateType = hooks.getTemplateForApp(appId)
const templateType = hooks.getTemplateForApp(appId)
if (templateType) {
DataSourceTemplate.create(templateType, [appAddress.toHexString()])
hooks.onAppTemplateCreated(appAddress, appId)
Expand All @@ -34,36 +36,36 @@ export function processToken(tokenAddress: Address): void {
}
}

function _isRegistered(address: Address, type: string): boolean {
let aragon = _getAragonInfo()
function _getAragonInfo(): AragonInfoEntity {
const aragonId = 'THERE_CAN_ONLY_BE_ONE'

let entities: Address[]
if (type == 'org') {
entities = aragon.orgs as Address[]
} else if (type == 'app') {
entities = aragon.apps as Address[]
} else if (type == 'token') {
entities = aragon.tokens as Address[]
} else {
throw new Error('Invalid entity type ' + type)
let aragon = AragonInfoEntity.load(aragonId)
if (!aragon) {
aragon = new AragonInfoEntity(aragonId)

aragon.orgs = []
aragon.apps = []
aragon.tokens = []

aragon.save()
}

return entities.includes(address)
return aragon
}

function _registerEntity(address: Address, type: string): void {
let aragon = _getAragonInfo()
const aragon = _getAragonInfo()

if (type == 'org') {
let entities = aragon.orgs
const entities = aragon.orgs
entities.push(address)
aragon.orgs = entities
} else if (type == 'app') {
let entities = aragon.apps
const entities = aragon.apps
entities.push(address)
aragon.apps = entities
} else if (type == 'token') {
let entities = aragon.tokens
const entities = aragon.tokens
entities.push(address)
aragon.tokens = entities
} else {
Expand All @@ -73,19 +75,22 @@ function _registerEntity(address: Address, type: string): void {
aragon.save()
}

function _getAragonInfo(): AragonInfoEntity {
let aragonId = 'THERE_CAN_ONLY_BE_ONE'

let aragon = AragonInfoEntity.load(aragonId)
if (!aragon) {
aragon = new AragonInfoEntity(aragonId)

aragon.orgs = []
aragon.apps = []
aragon.tokens = []
function _isRegistered(address: Address, type: string): boolean {
const aragon = _getAragonInfo()

aragon.save()
let entities: Bytes[]
if (type == 'org') {
entities = aragon.orgs
} else if (type == 'app') {
entities = aragon.apps
} else if (type == 'token') {
entities = aragon.tokens
} else {
throw new Error('Invalid entity type ' + type)
}

return aragon!
return entities.includes(address)
}



Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeployDAO as DeployDAOEvent } from '../../../generated/DAOFactory@0.6/DAOFactory'
import { DeployDAO as DeployDAOEvent } from '../../../generated/DAOFactory@0.8.1/DAOFactory'
import * as aragon from '../aragon'

export function handleDeployDAO(event: DeployDAOEvent): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-finance/subgraph/subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ templates:
abi: Finance
mapping:
kind: ethereum/events
apiVersion: 0.0.1
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- Transaction
Expand Down
Loading

0 comments on commit 577f62e

Please sign in to comment.