Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 2 additions & 46 deletions subgraph/src/FundingRoundFactoryMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { FundingRound as FundingRoundContract } from '../generated/FundingRoundF

import { OptimisticRecipientRegistry as RecipientRegistryContract } from '../generated/FundingRoundFactory/OptimisticRecipientRegistry'
import { BrightIdUserRegistry as BrightIdUserRegistryContract } from '../generated/FundingRoundFactory/BrightIdUserRegistry'
import { createRecipientRegistry } from './RecipientRegistry'

import {
FundingRound as FundingRoundTemplate,
Expand All @@ -31,48 +32,6 @@ import {
Token,
} from '../generated/schema'

function createRecipientRegistry(
fundingRoundFactoryAddress: Address,
recipientRegistryAddress: Address
): RecipientRegistry {
log.info('New recipientRegistry {}', [recipientRegistryAddress.toHex()])
let recipientRegistryId = recipientRegistryAddress.toHexString()
let recipientRegistry = new RecipientRegistry(recipientRegistryId)

recipientRegistryTemplate.create(recipientRegistryAddress)
let recipientRegistryContract = RecipientRegistryContract.bind(
recipientRegistryAddress
)
let baseDeposit = recipientRegistryContract.try_baseDeposit()
if (baseDeposit.reverted) {
recipientRegistry.baseDeposit = BigInt.fromI32(0)
recipientRegistry.challengePeriodDuration = BigInt.fromI32(0)
} else {
recipientRegistry.baseDeposit = baseDeposit.value
let challengePeriodDuration =
recipientRegistryContract.challengePeriodDuration()
recipientRegistry.challengePeriodDuration = challengePeriodDuration
}
let controller = recipientRegistryContract.try_controller()
let maxRecipients = recipientRegistryContract.try_maxRecipients()
let owner = recipientRegistryContract.try_owner()

if (!controller.reverted) {
recipientRegistry.controller = controller.value
}
if (!maxRecipients.reverted) {
recipientRegistry.maxRecipients = maxRecipients.value
}
if (!owner.reverted) {
recipientRegistry.owner = owner.value
}
recipientRegistry.fundingRoundFactory =
fundingRoundFactoryAddress.toHexString()
recipientRegistry.save()

return recipientRegistry
}

function createContributorRegistry(
fundingRoundFactoryAddress: Address,
contributorRegistryAddress: Address
Expand Down Expand Up @@ -191,10 +150,7 @@ function createOrUpdateFundingRoundFactory(
let recipientRegistryId = recipientRegistryAddress.toHexString()
let recipientRegistry = RecipientRegistry.load(recipientRegistryId)
if (!recipientRegistry) {
createRecipientRegistry(
fundingRoundFactoryAddress,
recipientRegistryAddress
)
createRecipientRegistry(fundingRoundFactoryId, recipientRegistryAddress)
}

let contributorRegistryAddress = fundingRoundFactoryContract.userRegistry()
Expand Down
9 changes: 5 additions & 4 deletions subgraph/src/OptimisticRecipientRegistryMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
RequestSubmitted,
} from '../generated/OptimisticRecipientRegistry/OptimisticRecipientRegistry'

import { Recipient, RecipientRegistry } from '../generated/schema'
import { Recipient } from '../generated/schema'
import { loadRecipientRegistry } from './RecipientRegistry'

// It is also possible to access smart contracts from mappings. For
// example, the contract that has emitted the event can be connected to
Expand Down Expand Up @@ -34,7 +35,7 @@ export function handleRequestResolved(event: RequestResolved): void {
log.info('handleRequestResolved', [])

let recipientRegistryId = event.address.toHexString()
let recipientRegistry = RecipientRegistry.load(recipientRegistryId)
let recipientRegistry = loadRecipientRegistry(event.address)
if (!recipientRegistry) {
log.warning(
'handleRequestResolved - ignore unknown recipient registry {} hash {}',
Expand Down Expand Up @@ -81,8 +82,8 @@ export function handleRequestSubmitted(event: RequestSubmitted): void {
log.info('handleRequestSubmitted', [])
let recipientRegistryId = event.address.toHexString()

let recipientRegistery = RecipientRegistry.load(recipientRegistryId)
if (!recipientRegistery) {
let recipientRegistry = loadRecipientRegistry(event.address)
if (!recipientRegistry) {
log.warning(
'handleRequestSubmitted - ignore unknown recipient registry {} hash {}',
[event.address.toHexString(), event.transaction.hash.toHex()]
Expand Down
78 changes: 78 additions & 0 deletions subgraph/src/RecipientRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Address, BigInt } from '@graphprotocol/graph-ts'
import { OptimisticRecipientRegistry as RecipientRegistryContract } from '../generated/OptimisticRecipientRegistry/OptimisticRecipientRegistry'

import { RecipientRegistry, FundingRoundFactory } from '../generated/schema'
import { OptimisticRecipientRegistry as RecipientRegistryTemplate } from '../generated/templates'

/*
* Create the recipient registry entity
*/
export function createRecipientRegistry(
fundingRoundFactoryId: string,
recipientRegistryAddress: Address
): RecipientRegistry {
let recipientRegistryId = recipientRegistryAddress.toHexString()
let recipientRegistry = new RecipientRegistry(recipientRegistryId)
RecipientRegistryTemplate.create(recipientRegistryAddress)

let recipientRegistryContract = RecipientRegistryContract.bind(
recipientRegistryAddress
)
let baseDeposit = recipientRegistryContract.try_baseDeposit()
if (baseDeposit.reverted) {
recipientRegistry.baseDeposit = BigInt.fromI32(0)
recipientRegistry.challengePeriodDuration = BigInt.fromI32(0)
} else {
recipientRegistry.baseDeposit = baseDeposit.value
let challengePeriodDuration =
recipientRegistryContract.challengePeriodDuration()
recipientRegistry.challengePeriodDuration = challengePeriodDuration
}
let controller = recipientRegistryContract.try_controller()
let maxRecipients = recipientRegistryContract.try_maxRecipients()
let owner = recipientRegistryContract.try_owner()

if (!controller.reverted) {
recipientRegistry.controller = controller.value
}
if (!maxRecipients.reverted) {
recipientRegistry.maxRecipients = maxRecipients.value
}
if (!owner.reverted) {
recipientRegistry.owner = owner.value
}
recipientRegistry.fundingRoundFactory = fundingRoundFactoryId
recipientRegistry.save()

return recipientRegistry
}

/*
* Load the recipient registry entity from the subgraph with the given address
*/
export function loadRecipientRegistry(
address: Address
): RecipientRegistry | null {
let recipientRegistryId = address.toHexString()
let recipientRegistry = RecipientRegistry.load(recipientRegistryId)
if (!recipientRegistry) {
let recipientRegistryContract = RecipientRegistryContract.bind(address)
let controller = recipientRegistryContract.try_controller()
if (!controller.reverted) {
// Recipient registry's controller must be the factory
let factoryId = controller.value.toHexString()
let factory = FundingRoundFactory.load(factoryId)
if (factory) {
/* This is our registry, create it */
recipientRegistry = createRecipientRegistry(factory.id, address)

// update factory
factory.recipientRegistry = recipientRegistryId
factory.recipientRegistryAddress = address
factory.save()
}
}
}

return recipientRegistry
}
13 changes: 0 additions & 13 deletions vue-app/src/api/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,6 @@ export async function getRecipientRegistryAddress(roundAddress: string | null):
}
}

export async function getCurrentRecipientRegistryAddress(): Promise<string> {
const data = await sdk.GetRecipientRegistryInfo({
factoryAddress: factory.address.toLowerCase(),
})

const registryAddress =
data.fundingRoundFactory?.currentRound?.recipientRegistry?.id ||
data.fundingRoundFactory?.recipientRegistry?.id ||
''

return registryAddress
}

export async function getProjects(registryAddress: string, startTime?: number, endTime?: number): Promise<Project[]> {
if (recipientRegistryType === 'simple') {
return await SimpleRegistry.getProjects(registryAddress, startTime, endTime)
Expand Down
6 changes: 4 additions & 2 deletions vue-app/src/views/RecipientProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@
</template>

<script setup lang="ts">
import { type Project, getProject, getCurrentRecipientRegistryAddress } from '@/api/projects'
import { type Project, getProject, getRecipientRegistryAddress } from '@/api/projects'
import { ensLookup } from '@/utils/accounts'
import { useAppStore } from '@/stores'
import { getBlockExplorerByAddress } from '@/utils/explorer'
import { getCurrentRound } from '@/api/round'

const route = useRoute()
const appStore = useAppStore()
Expand All @@ -86,7 +87,8 @@ const loading = ref<boolean>(true)

onMounted(async () => {
const recipientId = (route.params.id as string) || ''
const recipientRegistryAddress = await getCurrentRecipientRegistryAddress()
const currentRoundAddress = appStore.currentRoundAddress || (await getCurrentRound())
const recipientRegistryAddress = await getRecipientRegistryAddress(currentRoundAddress)

// retrieve the project information without filtering by the locked or verified status
const filter = false
Expand Down